Custom CursorAdapter and CheckBox states

那年仲夏 提交于 2019-12-08 14:37:34

Copy and paste

for(mCheckedState = new ArrayList<Boolean>(); !cursor.isAfterLast(); cursor.moveToNext()) {
    mCheckedState.add(cursor.getInt(cursor.getColumnIndex(Groceries.COLUMN_CHECKED)) != 0);
}

into a public helper method in your adapter class (i.e. public void populateAdapter()).

Then, in onLoadFinished swap the cursor in (with mAdapter.swapCursor(cursor)) and then call mAdapter.populateAdapter(). This will ensure that your Cursor is bound to the adapter before you attempt to populate mCheckedState.

That said, I'm not entirely sure what you are trying to do with mCheckedState in the first place... why can't you just check/uncheck the views directly using the Cursor in bindView?

The cursor isn't updated even when your database is unless you notify the cursor. What you'll want to do is have a separate structure in your adapter that keeps track of the clicked/non-clicked state and refer to that for the answer. If the answer isn't there, then refer to the cursor (which will be the case the first time you display the list).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!