After deleting from database my ListView does not update , I found a method on stackoverflow by it does not work, here is how I populate my list:
...
private ListView list;
ListAdapter adapter; (ListAdapter is a class from here i set the layout of a row)
...
...
protected void onCreate(Bundle savedInstanceState) {
...
...
database info = new database(this);
info.open();
data = info.getData2();
data2 = info.getData3();
info.close();
list=(ListView)findViewById(R.id.list);
adapter=new ListAdapter(this, data , data2);
list.setAdapter(adapter);
registerForContextMenu(list);
...
...
}
...
...
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info =(AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
...
...
if(menuItemName.equals("Delete")){
menuItemName = "2";
Log.i(TAG,"Primul "+listItemName + " " + " al doilea " + listItemName2);
database delete = new database(this);
delete.open();
delete.deleteEntryFromList(listItemName,listItemName2);
delete.close();
//here i am suposed to do
adapter.notifyDataSetChanged();
//but it does not work
}
}
Can somebody help me here ?
I always have problems with the notify methods. Easiest solution: Create a method that is called updateAdapter(), replace the notify call with that and put this in it:
Call that instead of the notify* method.