android listpreference 自定义,android – 自定义布局ListPreference

在您的preference.xml文件中,您可以通过类的全名来引用自定义ListPreference,即com.example.MyPreference

android:key="pref_wifi_key"

android:title="@string/settings">

android:key="pref_wifi_remove"

android:title="@string/remove_wifi"/>

android:title="@string/add_wifi"/>

然后你的类MyPreference应该是这样的:

import android.preference.ListPreference;

public class MyPreference extends ListPreference {

Context context;

public MyPreference(Context context, AttributeSet attrs) {

this.context = context;

setDialogLayoutResource(R.layout.yourLayout); //inherited from DialogPreference

setEntries(new CharSequence[] {"one", "two"});

setEntryValues(new CharSequence[] {"item1", "item2"});

}

protected void onDialogClosed(boolean positiveResult) {

Toast.makeText(context, "item_selected",

Toast.LENGTH_SHORT).show();

}

}

你可能感兴趣的:(android,listpreference,自定义)