开发者

Android: Display pop-up menu on certain action?

Ok so I know you can create a context menu when a user long clicks on开发者_如何学C an item...but can I make it so the pop-up menu appears when a user lets say double taps on the item or screen? Thanks


You could show an alert dialog like this:

private void showDialog()
{
   final CharSequence[] options = {"Option1", "Option2", "etc.."};

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Title here");

    builder.setItems(options, new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
           if (which == 0)//Option 1
           {
           }
           else if (which == 1)//Option 2
           {
           }
           //etc..
        } 
    });

    AlertDialog dlg = builder.create();
   dlg.show();
}


When you detect the gesture you want you can invoke showContextMenu() on the appropriate View which will use the same mechanisms as the context menus you're already familiar with. You should try to stay consistent with the platform when possible though. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜