Hello! I need a button to appear on the button with a choice on the ListView, but not to create a new Activity, but something like AlertDialog. How can this be implemented?

    2 answers 2

    import android.support.v7.widget.PopupMenu; PopupMenu popup = new PopupMenu(getActivity(), v); popup.getMenu().add(Menu.NONE, 0, Menu.NONE, "Пункт0"); popup.getMenu().add(Menu.NONE, 1, Menu.NONE, "Пункт1"); popup.show(); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case 0: //code break; case 1: //code break; } return true; } }); 

      If it's a matter of User Expirience, then create a new activity and set up a dialogue topic for it ("Theme.Dialog", for example). After that, load the layout with ListView inside and you will achieve the desired effect.

      If you absolutely do not want to add a new activity to the project, then the Dialog class with its setContentView() method will help you, thanks to which you can load the markup inside and interact with it.