Android - Popup menu when list item view pressed?

后端 未结 7 1550
逝去的感伤
逝去的感伤 2020-12-24 15:33

i would like to implement a popup menu similar to google\'s play store as shown below.

\"enter

相关标签:
7条回答
  • 2020-12-24 16:07

    Not sure if i understand you correctly but you can trigger this method to open a pop up dialog with a listview.

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Title if Any");
        builder.setItems(R.array.listoptions, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int itemClicked) {
                       String[] option_array = getResources().getStringArray(R.array.listoptions);
    
                       String optionSelected = option_array[itemClicked];
               }
        });
        return builder.create();
    }
    

    See Adding a List

     <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string-array name="listoption">
        <item>Install</item>
        <item>Add to listview</item>
    </string-array>
    </resources>
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题