I have a ListView with some elements. I want to retrieve the id of element that I run the contextual menu for (by long-clicking). But following code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_adapter);
/*non relevant code was omitted*/
registerForContextMenu(this.getListView());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo info){
Log.i("view", String.valueOf(v.findFocus().getId()) );
super.onCreateContextMenu(menu, v, info);
getMenuInflater().inflate(R.menu.activity_adapter_context_menu, menu);
}
returns always the same id, that is the id of ListView view and not ListView element id. I have tried some another options but coldn’t find the solution. How to sort it out?
if you want to get the list item id then use