开发者

How to refresh cursorAdapter especially when deleting last item in a list?

How to refresh cursorAdapter especially when deleting last item in a list?


scenario:

working:

  • editing list-view row, OK
  • adding list-view row, OK
  • deleting list-view row(one by one), until one is left, OK

problem:

  • deleting the last row/item, FAILED; you need to close first your activity and open it again for it to refresh.

I am using a cursor adapter, and I want to refresh its list when deleting the last row/item of a list view. my method for refreshing an adapter is to assign a new instance of cursorAdapter to my Listview(as if, doing this again and again).

code:

listview.setAdapter(new ImmunizationListCursorAdapter(
                    this,// current activity
                    R.layout.imm_list_row,// layout for each row
                    immunizationCursor,// the data
                    // Pass in the cursor to bind to.
                    // Array of cursor columns to bind to.
                    new String[] { ImmunizationModel.IM_COL_VACNAM开发者_如何学GoE,
                            ImmunizationModel.IM_COL_DATE },
                            // Parallel array of which template objects to bind to
                            // those
                            // columns.
                            new int[] { R.id.text_vaccine_name,
                            R.id.text_date_description }));

there it is.

any one who can help me? :((


All you need to do is to call productCursor.requery() after each modification to the dataset.

requery() automatically triggers execution of your query (in order to retrieve the new data) plus notification to the ListView (by the adapter) that it has to refresh itself.

BTW, until not so long ago I was using the same wrong method of assign a new instance of CursorAdapter...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜