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

     
  • 相关阅读:
    Windows Vista 桌面窗口管理器(1)
    Thinking in Java读书笔记――数组
    php图片上传存储源码,可实现预览
    php at(@)符号的用法简介
    Apache如何添加虚拟目录
    也发个PHP人民币金额数字转中文大写
    PHP Get Current URL
    Zend Studio下的PHP代码调试
    PHP url 加密解密函数
    使用新浪微博php SDK的一点记录
  • 原文地址:https://www.cnblogs.com/eyeandroid/p/2754419.html
Copyright © 2011-2022 走看看