我在首选项片段中有两个 Listpreference ,我想在第一次选择某些内容时刷新第二个 Listpreference 值。Listpreferences 是通过 Internet 填写的。
public class array extends PreferenceFragment {
public static String apref;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
final ListPreference array1Preference = (ListPreference)findPreference("array1");
setArray1PreferenceData(array1Preference);
array1Preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
setArray1PreferenceData(array1Preference);
return true;}});
final ListPreference array2Preference = (ListPreference)FindPreference("array2");
setArray2PreferenceData(array2Preference);
array2Preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
setArray2PreferenceData(array2Preference);
return true;}});
}
public void setArray1PreferenceData(ListPreference array1Preference) {
new LoadArray1().execute();
}
public void setArray2PreferenceData(ListPreference array2Preference) {
String CPref = "array1";
SharedPreferences prefs = this.getActivity().getSharedPreferences(
"com.asdd.ck_preferences", Activity.MODE_PRIVATE);
apref = prefs.getString(CPref, "");
if (apref != "0") {
new LoadArray2().execute();
} else {
new LoadArray1().execute();
}
}
public class LoadArray1 extends AsyncTask<String, String, String> {
}
public class LoadArray2 extends AsyncTask<String, String, String> {
}
}