Good all the time of day!

I have a ListView, and I want to attach a context menu to each of its elements. Often I saw in applications that the context menu for foliage elements is called when you click on a special button with three squares. I do not know the name of this button, so I can not even google it normally. This button looks like this:

alt text

Please tell me what the button is and how best to attach the context menu to each listview element? Thank!

    1 answer 1

    1. The button is called " overflow ". You can download it on the Internet, on habre was once a post referring to a pack with multi-colored icons.

    2. The menu is called " PopUpMenu ". To call it you need:

      1) Add the icon to the list item's layout, find it in the adapter and further:

       @Override public View getView(final int position, View convertView, ViewGroup parent) { //popUp menu holderMain.settings.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(context, v); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.mark_as_read: //действие return true; case R.id.share_link: //действие return true; case R.id.show_comments: //действие return true; default: return false; } } }); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.popup_menu, popup.getMenu()); popup.show(); } }); 

      2) Well, popup_menu.xml is also needed in the / res / menu folder

       <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/mark_as_read" android:orderInCategory="10" android:title="@string/mark_as_read"/> <item android:id="@+id/share_link" android:orderInCategory="50" android:title="@string/share_link"/> <item android:id="@+id/show_comments" android:orderInCategory="100" android:title="@string/show_comments"/> </menu> 
    • Well what a trouble with formatting ... = ( - YuriySPb
    • 2
      @Expert, try {summonModeratorForTextFromatting.help (); } catch (LazyModeratorException laaazy) {laaazy.helpMePlease (cookies); } finally {tryToDoItMyself (noNoNO, iCanT (doThis)); } - Yuriy SPb
    • @ YurySPb thanks! - JuniorTwo
    • @JuniorTwo, please) A couple of weeks ago, I did it all on the docks, knowing only the name of the button. - Yuriy SPb
    • But there is still a problem with this. How did you decide or ignore? - pavlofff