Android 共享引用不';我们不能拯救国家
我需要在应用程序中的设置,这将是在几个名称(都在一个项目)可用。我决定用如下方法创建类:Android 共享引用不';我们不能拯救国家,android,android-listview,sharedpreferences,android-preferences,Android,Android Listview,Sharedpreferences,Android Preferences,我需要在应用程序中的设置,这将是在几个名称(都在一个项目)可用。我决定用如下方法创建类: private SharedPreferences prefs; private Context context; public Preferenses(Context context){ this.context=context; } public void invertLanguageState(String lang){ prefs=context.getSharedPre
private SharedPreferences prefs;
private Context context;
public Preferenses(Context context){
this.context=context;
}
public void invertLanguageState(String lang){
prefs=context.getSharedPreferences(LEARN_WORDS_PREFS, Context.MODE_PRIVATE);
boolean state=prefs.getBoolean(lang, false);
Editor editor=prefs.edit();
editor.putBoolean(lang,!state);
editor.commit();
}
public void setLanguagesStates(String []langs,boolean []states){
prefs=context.getSharedPreferences(LEARN_WORDS_PREFS, Context.MODE_PRIVATE);
Editor editor=prefs.edit();
final int size=states.length;
for(int i=0;i<size;i++){
editor.putBoolean(langs[i],states[i]);
}
editor.commit();
}
public boolean [] getLanguagesStates(String []keys){
prefs=context.getSharedPreferences(LEARN_WORDS_PREFS,Context.MODE_PRIVATE);
final int size=keys.length;
boolean [] states=new boolean[size];
for(int i=0;i<size;i++){
states[i]=prefs.getBoolean(keys[i], false);
}
return states;
}
private SharedPreferences优先权;
私人语境;
公众偏好(上下文){
this.context=context;
}
公共语言状态(字符串lang){
prefs=context.getSharedReferences(学习单词prefs,context.MODE\u PRIVATE);
boolean state=prefs.getBoolean(lang,false);
编辑器编辑器=prefs.edit();
编辑器.putBoolean(lang,!state);
commit();
}
public void setLanguagesStates(字符串[]langs,布尔[]状态){
prefs=context.getSharedReferences(学习单词prefs,context.MODE\u PRIVATE);
编辑器编辑器=prefs.edit();
最终整数大小=states.length;
对于(int i=0;i如果我没有误解
checkBox.setSelected(states[position]);
您需要设置复选框的checked
属性。checkbox.setChecked(布尔)
从文档:
setChecked(boolean)
更改视图的选中状态
问题是checkBox.setSelected(states[position]);insteed checkBox.setChecked(states[position])@abpath states[position]是布尔值吗?
setChecked(boolean)