如何在setViewValue上更新游标?

时间:2013-11-24 11:14:08

标签: android android-listview

有没有办法从setViewValue代码手动更新游标的项目值?目前我只是再次获取所有记录,然后changeCursornotifyDataSetChanged,但速度非常慢:

dbHelper = new DbAdapter(this);
dbHelper.open();
recordsCursor = dbHelper.fetchAllRecords();
startManagingCursor(recordsCursor);

String[] from = new String[]{DbAdapter.KEY_1, DbAdapter.KEY_2};
int[] to = new int[]{R.id.text1, R.id.background};

adapter = new SimpleCursorAdapter(this, R.layout.row, recordsCursor, from, to);

if (adapter != null) {
    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

            int viewId = view.getId();
            switch(viewId) {
            case R.id.text1:
                final Object item = adapter.getItem(cursor.getPosition());
                ... 
                // some logic is here, so the code below is run only when item is displayed for 5 seconds
                dbHelper.open();
                Boolean result = dbHelper.markRecordAsRead(text); // update the database
                ... 
                // the code below works, but since I read the whole database, it is SLOW
                dbHelper.open();
                recordsCursor = dbHelper.fetchAllRecords();
                adapter.changeCursor(recordsCursor);
                adapter.notifyDataSetChanged();
                // is there any way just to update the cursor's item value?

0 个答案:

没有答案