update the listview after inserting a new record with simpleCursorAdapter - requery()

后端 未结 1 699
误落风尘
误落风尘 2021-01-23 16:12

I understand the requery() mechanic, but i do not understand the implementation:

protected void onCreate(Bundle savedInstanceState) {
        super.         


        
相关标签:
1条回答
  • 2021-01-23 17:00

    the requery cursor method is deprecated. but you're right you have to reload the cursor and then make sure that your new cursor is being presented to your ListView. for a quick 'n dirty solution, I suggest you make your adapter a field. and then use the following method:

    private void requery() {
        Cursor values = datasource.getAllCategorie();
        adapter.changeCursor(values);
    }
    

    What it does is remake a cursor. then by calling changeCursor you swap the old cursor for the new one and the old one is closed automatically. at the very least, you save yourself from making a new adapter. The more sophicated approach with all the trim and fixes i suppose would be to implement a CursorLoader which would perform the process automatically when the database content has been changed.

    0 讨论(0)
提交回复
热议问题