你们能解释一下为什么cursor
每行都通过引用作为不同的实例最终mDBHelper.updateFavorites()
指向它的最新位置吗?因为我期望cursor
传递给onClick()
方法实际上Cursor c
是指向该对象传递时的位置,但事实并非如此。非常感谢你。
@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
View row;
final Cursor cursor = c; // This is different for each row in list view
LayoutInflater inflater = ((Activity) ctxt).getLayoutInflater();
row = inflater.inflate(R.layout.row, parent, false);
this.defaultDrawable = (Drawable) row.getBackground();
final CheckBox mStar = (CheckBox) row.findViewById(R.id.star);
mStar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mStar.isChecked()) {
mDbHelper.updateFavorite(cursor, 1); // Here I'm expecting to have the cursor pointing exactly where Cursor c (which is passed to newView() method) is pointing right now.
} else {
mDbHelper.updateFavorite(cursor, 0); // The same here
}
}
});
ViewHolder holder = new ViewHolder(row);
row.setTag(holder);
return (row);
}