我只想创建一个按钮,其中一个按钮应该在那里,当点击此按钮时,应该出现一个带有两个可点击单选按钮的对话框。如何制作这样的UI?
答案 0 :(得分:0)
用于创建像这样的警告对话框。在按钮单击监听器中调用此方法。
private void showDialog() {
final CharSequence[] Countries = { "India", "U.S.A", "U.K" };
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setIcon(R.drawable.icon);
alt_bld.setTitle("Select Country");
//you can set the Default selected value of the list, Here it is 0 means India
alt_bld.setSingleChoiceItems(Countries, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getBaseContext(), Countries[item],
Toast.LENGTH_LONG).show();
alert.cancel();
}
});
alert = alt_bld.create();
alert.show();
}