Normally for ListViews
, I would do this when I wanted to get the position that the user clicked on a Context Menu.
public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
position = info.position;
However, ever since I switched to a RecycleView
, I now get a null pointer here.
The code above is in my main Activity
(Fragment
) while onCreateContextMenu()
is done in the adapter
as per the new way.
ItemView.setOnCreateContextMenuListener(this);
is also done in the adapter (specifically the constructor).