目前我做到以下幾點:如何在數據庫值更改的情況下更新ListView?
1)數據庫鏈接到ListView控件:
String[] from = new String[]{DbAdapter.KEY_TITLE,
DbAdapter.KEY_DISPLAYED_VALUE,
DbAdapter.KEY_FAVORITE};
int[] to = new int[]{R.id.name, R.id.time, R.id.icon};
items = new SimpleCursorAdapter(this, R.layout.row, itemsCursor, from, to);
2)KEY_DISPLAYED_VALUE
在數據庫中每2秒改變。然後調用items.notifyDataSetChanged()
。但屏幕上的數據沒有更新(R.id.time
目前爲TextView
,一旦此代碼有效,將爲TextSwitcher
)。
數據庫更新爲execSQL。