1

I have a settings menu in my application. When I click Menu button, I can click on settings icon and setting activity appears. Settings layout contains a listview, each list view item consists of textview (description of setting) and edittext (setting data). I store the data in settings table in SQLite database and add all of the settings to an adapter (ListAdapter) and listView like this:

Cursor cursor = dbAdapter.fetchSettings();
startManagingCursor(cursor);
String[] from = new String[] { "description", "data" };
int[] to = new int[] { R.id.settingsDesc, R.id.settingsText };
listAdapter = new SimpleCursorAdapter(this,
R.layout.settings_menu_item, cursor, from, to);
listView.setAdapter(listAdapter);

As you see I can change the setting data. My question is, how can I update the database when I have changed the text in any of the edittext elements? I also have Save button in Settings layout and I want that clicking on it would update the database. I hope there is a simple way to do it.

4

1 回答 1

0

您可以获取所选 editText 值的 id 并触发将更新数据库的更新查询。cursor.requery()然后,您可以使用and 重新填充 ListView notifyDataSetChanged()

所以,在保存按钮上

1.) Fire the update query for the selected row.
2.) cursor.requery();
3.) adapter.notifyDataSetChanged();
于 2011-12-14T09:28:45.317 回答