EyeAndroid

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1. 范例说明

 

  • 在先前介绍的范例中,提到了一个神奇的“AlertDialog”对话框,这个对话框也可以包含对话框,即层层叠叠的AlertDialog。
  • 本范例将示范如何利用一个按钮事件,在触发这个按钮事件后,再通过类似列表项目的方式呈现在AlertDialog里,一般可用作投票、选择器和遥控器等类似的范例,最后再返回程序,取得User选择的菜单项目结果。

 

2. 运行结果

3. 编写代码

 

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) */
	};


4. 扩展学习与作业

 

自己动手写该Demo

视频讲解:http://www.eyeandroid.com/thread-9952-1-1.html

 
posted on 2012-11-04 23:57  EyeAndroid  阅读(362)  评论(0编辑  收藏  举报