Header ContextMenu & # 8594; get from click listView item

Trying to set the ContextMenu header to match the ListView item. ListView contains bookmark list → FAVICON + BOOKMARK TITLE

@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      menu.add(0, EDIT_ID, 0, R.string.menu_edit);
      menu.add(0, DELETE_ID, 0, R.string.menu_delete);
      menu.add(0, SHARE_ID, 0, R.string.menu_share);

      AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
      View itemID = (info.targetView);
      menu.setHeaderTitle("bla" + itemID);
    }

When I run this code, it shows android.widget.RelativeLayout@423d2389or something else, and if I change itemIDto String itemID = ((TextView) info.targetView).getText().toString();, I will get a power connection with a long click, even if errors are not displayed in Eclipse or when I start the application.

I also want to get the icon the same way ...

Appreciate the help!

+3
source share
1 answer

info.targetView - RelativeLayout, TextView. android: id TextView (, android: id = "@android: id/title" ), :

String title = ((TextView) info.targetView.findViewById(android.R.id.title)).getText();
+5

Source: https://habr.com/ru/post/1765193/


All Articles