I can't get this to work, I have looked through many posts and I really am desperate since I have to finish this until the day after tomorrow. The problem is the following:
I have a listView with entries from a database. It is possible to do a long click on them to call a contextMenu. In the context menu I can either delete or edit the entry, and to do that I need the id of the selected item.
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater2 = getMenuInflater();
inflater2.inflate(R.menu.edit_grade_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int id = (int) info.id;
switch (item.getItemId()) {
case R.id.edit_grade:
Intent i = new Intent(this, AddGradeActivity.class);
i.putExtra(GradesDbAdapter.KEY_ROWID, linkSubject);
// putExtra edit, so addGradeActivity knows it has to fill views with values to edit grade
i.putExtra("edit", true);
i.putExtra(GradesDbAdapter.KEY_GRADE, id);
this.startActivity(i);
finish();
return true;
case R.id.del_grade:
myDbHelper.deleteGradeEntry(id, semester);
// filldata to refresh listview
fillData();
return true;
default:
return super.onContextItemSelected(item);
}
}
Now my problem is that this id that I get from info always is 0. It's really weird since it has worked before I changed the layout, I have this same activity running in 2 tabs on the same screen. Could this be the reason?