zoukankan      html  css  js  c++  java
  • 【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

     
  • 相关阅读:
    嵌入式工程师为何不用学习C++语言?
    汽车电子基础知识
    为什么寄存器比存储器快?
    数字信号和模拟信号
    JLink和JTag的区别
    C++中static关键字作用总结
    所谓高情商,就是会说话
    汽车电子缩略语及术语
    卷积
    算法整理
  • 原文地址:https://www.cnblogs.com/eyeandroid/p/2754419.html
Copyright © 2011-2022 走看看