Reputation: 3122
I have question for list-view please see my below code
private void set_adapter() {
Cursor list_scan_curson = scan_result.getScanResult();
List<String> list_scan = new ArrayList<String>();
try {
if (list_scan_curson.moveToFirst()) {
do {
String name = list_scan_curson.getString(0);
// Adding contact to list
list_scan.add(name);
} while (list_scan_curson.moveToNext());
}
ArrayAdapter<String> list_item_scan = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list_scan);
this.list_scan.setAdapter(list_item_scan);
} catch (Exception e) {
}
}
now i want to change or update adapter when my database update and based on that list-view will update so can any buddy tell me how to do this
Upvotes: 1
Views: 6569
Reputation: 311
If you want to update data from list use adapter.notifyDataSetChanged()
. If you want to update data from database you have to trigger some actions so use onScrollchanged
listener or use some background thread.
Upvotes: 1
Reputation: 5825
You create a new cursor, and replace the old one, something like this:
Private ArrayAdapter<String> mAdapter; // adapter declared as field
...
mAdapter = ..., // create adapter
...
mAdapter.notifyDataSetChanged(); // update listview
Upvotes: 2
Reputation: 3177
You can implement some logic like below[checkIstheDataVersionChanged(Object CurrentVersion)
] to check what type of change/update will affect your dataset and reload the listView using set_adapter.
boolean isDataSetChanged = checkIstheDataVersionChanged(Object CurrentVersion);
if(isDataSetChanged )
{
set_adapter();
}
Upvotes: 0