[b]1. 范例说明[/b]
在先前介绍的范例中,提到了一个神奇的“AlertDialog”对话框,这个对话框也可以包含对话框,即层层叠叠的AlertDialog。
本范例将示范如何利用一个按钮事件,在触发这个按钮事件后,再通过类似列表项目的方式呈现在AlertDialog里,一般可用作投票、选择器和遥控器等类似的范例,最后再返回程序,取得User选择的菜单项目结果。
[b]2. 运行结果[/b]
[img]http://dl.iteye.com/upload/attachment/0076/1590/f5f561f3-bb10-3eba-97cf-79e675c2c8b8.png[/img]
[b]3. 编写代码[/b]
Button.OnClickListener myShowAlertDialog = new Button.OnClickListener() {
public void onClick(View arg0) {
new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.str_alert_title)
.setItems(R.array.items_irdc_dialog,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichcountry) {
CharSequence strDialogBody = getString(R.string.str_alert_body);
String[] aryShop = getResources()
.getStringArray(
R.array.items_irdc_dialog);
new AlertDialog.Builder(MainActivity.this)
.setMessage(
strDialogBody
+ aryShop[whichcountry])
.setNeutralButton(
R.string.str_ok,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int whichButton) {
dialog.dismiss();
/* 在这里处理要作的事 */
}
}).show();
}
})
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
d.dismiss();
}
}).show();
} /* End: public void onClick(View arg0) */
};
[b]4. 扩展学习与作业[/b]
自己动手写该Demo
[b][size=large]视频讲解:[/size][/b][url]http://www.eyeandroid.com/thread-9952-1-1.html[/url]
在先前介绍的范例中,提到了一个神奇的“AlertDialog”对话框,这个对话框也可以包含对话框,即层层叠叠的AlertDialog。
本范例将示范如何利用一个按钮事件,在触发这个按钮事件后,再通过类似列表项目的方式呈现在AlertDialog里,一般可用作投票、选择器和遥控器等类似的范例,最后再返回程序,取得User选择的菜单项目结果。
[b]2. 运行结果[/b]
[img]http://dl.iteye.com/upload/attachment/0076/1590/f5f561f3-bb10-3eba-97cf-79e675c2c8b8.png[/img]
[b]3. 编写代码[/b]
Button.OnClickListener myShowAlertDialog = new Button.OnClickListener() {
public void onClick(View arg0) {
new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.str_alert_title)
.setItems(R.array.items_irdc_dialog,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichcountry) {
CharSequence strDialogBody = getString(R.string.str_alert_body);
String[] aryShop = getResources()
.getStringArray(
R.array.items_irdc_dialog);
new AlertDialog.Builder(MainActivity.this)
.setMessage(
strDialogBody
+ aryShop[whichcountry])
.setNeutralButton(
R.string.str_ok,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int whichButton) {
dialog.dismiss();
/* 在这里处理要作的事 */
}
}).show();
}
})
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
d.dismiss();
}
}).show();
} /* End: public void onClick(View arg0) */
};
[b]4. 扩展学习与作业[/b]
自己动手写该Demo
[b][size=large]视频讲解:[/size][/b][url]http://www.eyeandroid.com/thread-9952-1-1.html[/url]