1
私はいくつかのチェックボックスのIDを持つ配列を持っています。 onResume
私は、これらのチェックボックスのブール値がビューを適合させるためにtrue
またはfalse
(ループを使用)であるかどうかをチェックしたいと思います。ここに私のコードがあります。それはすべての値がfalse
であることを私に知らせるので、うまくいきません。誰かがなぜこれが起こっているのか教えてもらえますか? Android:オブジェクトのSharedPreferencesを動的に取得する方法
ArrayList<Integer> boxArray = new ArrayList<Integer>();
boxArray.add(R.id.boxA);
boxArray.add(R.id.boxB);
boxArray.add(R.id.boxC);
そしてonReturn
で
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(this);
for (int i=0; i<boxArray.size(); i++) {
if (preferences.getBoolean
(findViewById(boxArray.get(i)).toString(), false) == true) {
//change the view of the checkbox to checked if its value is true
CheckBox currentBox = (CheckBox) findViewById(boxArray.get(i));
currentBox.setChecked(true);
}
}