我尝试使用每行上的复选框为 ListView 创建自己的适配器。一切正常,但问题是,当我选中某个复选框然后向下滚动时,另一个也被选中。
(当我第一次检查时,11 日,21 日,...,也被检查了)我能解释一下问题出在哪里吗?
谢谢你。
我的适配器:
public class WordAdapter extends CursorAdapter {
public WordAdapter(Context context, Cursor cursor, int flags){
super(context, cursor, flags);
}
@Override
public void bindView(View oldView, Context ctx, Cursor c) {
int wordQuestionIndex = c.getColumnIndex( WordDBAdapter.QUESTION );
int wordAnswerIndex = c.getColumnIndex( WordDBAdapter.ANSWER );
int activeIndex = c.getInt(c.getColumnIndex( WordDBAdapter.ACTIVE ));
String question = c.getString(wordQuestionIndex);
String answer = c.getString(wordAnswerIndex);
int active = c.getInt(activeIndex);
Log.d("WordAdapter", "isActive: "+ active + " - " + question + ", " + answer);
((TextView) oldView.findViewById(R.id.adapter_question)).setText(question);
((TextView) oldView.findViewById(R.id.adapter_answer)).setText(answer);
CheckBox checkBox =(CheckBox) oldView.findViewById(R.id.myCheckBox);
//checkBox.setChecked(vh.isChecked);
}
@Override
public View newView(Context ctx, Cursor c, ViewGroup root) {
LayoutInflater inflater = LayoutInflater.from(ctx);
View view = inflater.inflate(R.layout.word, root, false);
return view;
}
}