我尝试为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;
}
}
答案 0 :(得分:1)