私は、ビューリサイクルの結果として生じる望ましくないランダムチェックを防ぐために、を手動で更新するオーバーライドされたgetView
メソッドを持つ単純なアダプタを持っています。だから私はそれぞれcheckbox
のためにsetChecked(boolean)
を置くが、それでも正しく更新されない。私はブール値が何であるかを見るためにLogステートメントを使用しており、checkboxes
はブール値と同じではありません。誰にも何か提案はありますか?ListViewのチェックボックスが正しく更新されない
ありがとうございます!ここ
コード:あなたは、スイッチの句の前にboxer.setChecked(偽)を設定
adapter = new SimpleAdapter(this, list, R.layout.rowsecond,
new String[] { "icon", "name", "checkbox" }, new int[] {
R.id.image1, R.id.text1, R.id.checkbox }) {
public View getView(int position, View convertView, ViewGroup parent) {
// View v = super.getView(position, convertView, parent);
View v = convertView;
if (v == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.rowsecond, null);
}
ImageView imgV = (ImageView)v.findViewById(R.id.image1);
imgV.setImageDrawable(getResources().getDrawable(((Integer)list.get(position).get("icon")).intValue()));
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText((String)list.get(position).get("name"));
list.get(position).get("icon");
boxer = (CheckBox) v.findViewById(R.id.checkbox);
//
boxer.setTag(new Integer(position));
switch(position)
{
case 0:
boxer.setChecked(CategoriesFirst.fr_one);
break;
case 1:
boxer.setChecked(CategoriesFirst.fr_two);
break;
case 2:
boxer.setChecked(CategoriesFirst.fr_three);
break;
case 3:
boxer.setChecked(CategoriesFirst.fr_four);
break;
case 4:
boxer.setChecked(CategoriesFirst.fr_five);
break;
case 5:
boxer.setChecked(CategoriesFirst.fr_six);
break;
case 6:
boxer.setChecked(CategoriesFirst.fr_seven);
break;
case 7:
boxer.setChecked(CategoriesFirst.fr_eight);
break;
case 8:
boxer.setChecked(CategoriesFirst.fr_nine);
break;
case 9:
boxer.setChecked(CategoriesFirst.fr_ten);
break;
case 10:
boxer.setChecked(CategoriesFirst.fr_eleven);
break;
case 11:
boxer.setChecked(CategoriesFirst.fr_twelve);
break;
case 12:
boxer.setChecked(CategoriesFirst.fr_thirteen);
break;
case 13:
boxer.setChecked(CategoriesFirst.fr_fourteen);
break;
}
boxer.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Integer posSelected = (Integer) buttonView.getTag();
int posSelectedint = posSelected.intValue();
switch (posSelectedint) {
// set static booleans
// REMEMBER BREAKS!
case 0:
CategoriesFirst.fr_one = !CategoriesFirst.fr_one;
break;
case 1:
CategoriesFirst.fr_two = !CategoriesFirst.fr_two;
break;
case 2:
CategoriesFirst.fr_three = !CategoriesFirst.fr_three;
break;
case 3:
CategoriesFirst.fr_four = !CategoriesFirst.fr_four;
break;
case 4:
CategoriesFirst.fr_five = !CategoriesFirst.fr_five;
break;
case 5:
CategoriesFirst.fr_six = !CategoriesFirst.fr_six;
break;
case 6:
CategoriesFirst.fr_seven = !CategoriesFirst.fr_seven;
break;
case 7:
CategoriesFirst.fr_eight = !CategoriesFirst.fr_eight;
break;
case 8:
CategoriesFirst.fr_nine = !CategoriesFirst.fr_nine;
break;
case 9:
CategoriesFirst.fr_ten = !CategoriesFirst.fr_ten;
break;
case 10:
CategoriesFirst.fr_eleven = !CategoriesFirst.fr_eleven;
break;
case 11:
CategoriesFirst.fr_twelve = !CategoriesFirst.fr_twelve;
break;
case 12:
CategoriesFirst.fr_thirteen = !CategoriesFirst.fr_thirteen;
break;
case 13:
CategoriesFirst.fr_fourteen = !CategoriesFirst.fr_fourteen;
break;
default:
break;
}
CategoriesFirst.save("fr_one",
CategoriesFirst.fr_one);
CategoriesFirst.save("fr_two",
CategoriesFirst.fr_two);
CategoriesFirst.save("fr_three",
CategoriesFirst.fr_three);
CategoriesFirst.save("fr_four",
CategoriesFirst.fr_four);
CategoriesFirst.save("fr_five",
CategoriesFirst.fr_five);
CategoriesFirst.save("fr_six",
CategoriesFirst.fr_six);
CategoriesFirst.save("fr_seven", CategoriesFirst.fr_seven);
CategoriesFirst.save("fr_eight", CategoriesFirst.fr_eight);
CategoriesFirst.save("fr_nine", CategoriesFirst.fr_nine);
CategoriesFirst.save("fr_ten", CategoriesFirst.fr_ten);
CategoriesFirst.save("fr_eleven", CategoriesFirst.fr_eleven);
CategoriesFirst.save("fr_twelve", CategoriesFirst.fr_twelve);
CategoriesFirst.save("fr_thirteen", CategoriesFirst.fr_thirteen);
CategoriesFirst.save("fr_fourteen", CategoriesFirst.fr_fourteen);
}
});
return v;
}
};
はい、それが問題を悪化させました。スクロールするとリストが非常に遅くなります。スクロールするとすぐに十分に確認できないようです – mikez