【发布时间】:2012-07-14 11:16:47
【问题描述】:
我只想制作一个应该有一个按钮的用户界面,当单击此按钮时,应该会出现一个带有两个可单击单选按钮的对话框。如何制作这样的用户界面?
【问题讨论】:
标签: android android-ui android-button android-dialog
我只想制作一个应该有一个按钮的用户界面,当单击此按钮时,应该会出现一个带有两个可单击单选按钮的对话框。如何制作这样的用户界面?
【问题讨论】:
标签: android android-ui android-button android-dialog
用于创建像这样的警报对话框。在您的按钮单击侦听器中调用此方法。
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();
}
【讨论】: