Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 共享引用不';我们不能拯救国家_Android_Android Listview_Sharedpreferences_Android Preferences - Fatal编程技术网

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)