I've added data into my SQLite database, and it shows inside listView. But I want to delete it with Context menu. Context menu is showing, but data is not deleted.
Here is sample of my code:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
mDataBase = dbHelper.getWritableDatabase();
switch(item.getItemId()) {
case R.id.delete:
mDataBase.delete("orderTable", "_id" + " =? ", new String[] {String.valueOf(info.id)});
dbAdaper.setArrayMyData(selectAll());
dbAdaper.notifyDataSetChanged();
mDataBase.close();
}
return super.onContextItemSelected(item);
}
I found out that info.id has 0 value.
dbAdaper = new DBBasketAdapter(getActivity(), selectAll());
listView.setAdapter(dbAdaper);
registerForContextMenu(listView);