Android: how to use CursorAdapter?

后端 未结 2 698
鱼传尺愫
鱼传尺愫 2020-12-07 16:03

I have a database, a ListView, and a CustomCursorAdapter that extends CursorAdapter. A menu button adds an item to the database. I wan

2条回答
  •  渐次进展
    2020-12-07 16:46

    I created next method for ListView updating:

    /**
     * Method of refreshing Cursor, Adapter and ListView after database 
     * changing
     */
    public void refreshListView() {
        databaseCursor = db.getReadableDatabase().query(
                CurrentTableName, 
                null, 
                null, 
                null, 
                null, 
                null, 
                "title"+SortingOrder);
        databaseListAdapter = new DomainAdapter(this, 
                android.R.layout.simple_list_item_2, 
                databaseCursor, 
                new String[] {"title", "description"}, 
                new int[] { android.R.id.text1, android.R.id.text2 });
        databaseListAdapter.notifyDataSetChanged();
        DomainView.setAdapter(databaseListAdapter);
    }
    

    end calls it each time after some changing in database

提交回复
热议问题