之后,按一下按钮Android的开放上下文菜单 [英] Android opening context menu after button click

查看:126
本文介绍了之后,按一下按钮Android的开放上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开快捷菜单,当我点击一个按钮,但我也必须知道哪些列表项的重点是,当我按一下按钮。你知道该怎么做?什么code应该在的onclick 的方法?

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 be in onclick method?

推荐答案

我一直在寻找相同的,并且发现,而不是上下文菜单,你应该使用对话框

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();

<一个href="http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog">http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog

这篇关于之后,按一下按钮Android的开放上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆