安卓:创建一个弹出窗口,有多个选择项 [英] Android: create a popup that has multiple selection options
问题描述
我一直在寻找周围试图找出如何创建一个弹出或具有4个选项可供选择的对话框。
I've been searching around trying to figure out how to create a popup or a dialog that has 4 options to choose from.
我看到这张照片在Android开发者网站:
I see this picture on the Android developer site:
有谁知道如何code起来有点像一个在右边?我不需要任何图标旁边,我的文字,我只需要能够从4个选项中进行选择。
Does anyone know how to code up something like the one on the right? I don't need any icons next to my text, I just need to be able to select from 4 options.
推荐答案
您可以创建一个的CharSequence
阵列要显示那里,然后将数组传递给选项一个 AlertDialog.Builder
的方法 setItems(CharSequence的[],DialogInterface.OnClickListener)
。
You can create a CharSequence
array with the options you want to show there and then pass the array to an AlertDialog.Builder
with the method setItems(CharSequence[], DialogInterface.OnClickListener)
.
一个例子:
CharSequence colors[] = new CharSequence[] {"red", "green", "blue", "black"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(colors, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on colors[which]
}
});
builder.show();
输出(在Android 4.0.3):
The output (on Android 4.0.3):
(背景图不包括在内。))
(Background map not included. ;))
这篇关于安卓:创建一个弹出窗口,有多个选择项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!