calling checkboxpreference from preferenceScreen

Xiaosheng Wu

New member
Jun 22, 2016
1
0
0
I am trying to make a setting menu, I want the fragment to call a preference screen when I touch the key, here's how I implements part of my codes:

ArrayList<String> items= new ArrayList<String>() {{
add("A");
add("B");
add("C");
}};

android.support.v7.preference.PreferenceManager cmdScr =getPreferenceManager();
android.support.v7.preference.PreferenceScreen screen = (android.support.v7.preference.PreferenceScreen) cmdScr.getPreferenceScreen().findPreference(KEY);

for (String item: items) {
Log.e(TAG,"CREATING Preferences");
android.support.v7.preference.CheckBoxPreference cpref = new android.support.v7.preference.CheckBoxPreference(this.getContext());
cpref.setTitle(item);
//cpref.setKey("The Name");
cpref.setChecked(true);
screen.addPreference(cpref);

}//setPreferenceScreen(screen);

} // if I un-comment the setPreferenceScreen(screen) then it shows the list once I enters the setting
//and the there's only one list of A B C without checkbox... weird
I tried the same method in another app and it works, the only difference is that I places the same code in the Oncreate method of another activity, whereas in the example above I am in a fragment extending PreferenceFragmentCompat... Thanks
 

Trending Posts

Forum statistics

Threads
957,002
Messages
6,970,975
Members
3,163,679
Latest member
prospero44