【Android每日一讲】2012.11.05 今晚到哪儿打牙祭 - 具有选择功能的对话框

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值