嗨朋友,我想要像图像中一样的警报对话框(只有文本而不是单选按钮),但我不想要单选按钮,我只需要文本,我该怎么做,请建议我。
问问题
116 次
2 回答
1
final CharSequence[] items = {"One", "Two", "Three"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
}
});
builder.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Do something when ok pressed
}
});
builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Do something when cancel pressed
}
});
AlertDialog alert = builder.create();
alert.show();
于 2012-11-20T10:22:48.117 回答
0
试试这个代码
final CharSequence[] version = {"Jelly Bean", "IceCream Sandwich", "Honey Comb", "Ginger Bread"};
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setTitle("Choose your version");
ad.setMessage("You can set messag here");
ad.setItems(version, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int intVersion)
{
}
ad.setPositiveButton("OK", new OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int arg1)
{
}
}
ad.setNegativeButton("Cancel", new OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int arg1)
{
}
});
ad.setCancelable(false);
ad.show();
于 2012-11-20T10:31:26.707 回答