Android opening context menu after button click

后端 未结 4 1023
余生分开走
余生分开走 2020-12-30 00:16

I want to open context menu when I click a button, but also I have to know which list item is focused when I click the button. Do you know how to do that? What code should b

4条回答
  •  太阳男子
    2020-12-30 01:03

    I was looking for the same, and found that instead of context menu, you should use Dialogs

    final CharSequence[] items = {"Red", "Green", "Blue"};
    
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Pick a color");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
    

    http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog

提交回复
热议问题