package irdc.ex03_20;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.TextView;public class EX03_20 extends Activity{  public Button mButton1;  public TextView mTextView1;  /** Called when the activity is first created. */  @Override  public void onCreate(Bundle savedInstanceState)  {    super.onCreate(savedInstanceState);    //加载视图    setContentView(R.layout.main);    //视图控件和对应的类绑定    mButton1 = (Button) findViewById(R.id.myButton1);    mTextView1 = (TextView) findViewById(R.id.myTextView1);    //给按钮设置监听程序,监听类在下面    mButton1.setOnClickListener(myShowAlertDialog);  }  /**   * 设置监听程序A   */  Button.OnClickListener myShowAlertDialog = new Button.OnClickListener()  {    public void onClick(View arg0)    {      /**       * AlertDialog.Builder 内部类       * setTitle方法设置对话框的标题       * setItems方法设置一个类表,并给列表中的元素设置监听程序B       */      new AlertDialog.Builder(EX03_20.this).setTitle(R.string.str_alert_title)          .setItems(R.array.items_irdc_dialog,              new DialogInterface.OnClickListener() //我是监听程序B              {                public void onClick(DialogInterface dialog, int whichcountry)                {                  //strDialogBody的值为:“你选择的是:”                  CharSequence strDialogBody = getString(R.string.str_alert_body);                                    //aryShop的值为:[盖浇饭, 水饺, 西红柿炒蛋]                  String[] aryShop = getResources().getStringArray(                      R.array.items_irdc_dialog);                                    //设置再次弹出的对话框,内容主体为上面两个值拼接,                  //whichcountry对应方法的形参,应该底层自动监听点击的是哪个选项                  new AlertDialog.Builder(EX03_20.this).setMessage(                      strDialogBody + aryShop[whichcountry]).setNeutralButton( //设置一个监听程序                      R.string.str_ok, new DialogInterface.OnClickListener()                      {                        public void onClick(DialogInterface dialog,                            int whichButton)                        {                                                 }                      }).show();                }              }).setNegativeButton("come on",              new DialogInterface.OnClickListener()              {                public void onClick(DialogInterface d, int which)   //设置一个监听程序                {                  d.dismiss();                }              }).show();    } /* End: public void onClick(View arg0) */  };  }

android例子分析-1

更多相关文章

  1. Android中NDK的使用方法
  2. android:编写属性动画程序(旋转,缩放,淡出淡入)
  3. Android的window类的常用方法
  4. Android 监听程序的安装、卸载、替换
  5. Android获取开机启动程序列表
  6. Android记事本程序源码
  7. Android 拨打webView 里面的电话号码的方法
  8. android 在线视频播放器实现方法
  9. Android下各文件方法获取的路径

随机推荐

  1. [置顶] Android调试工具之adbs
  2. Android:子线程向UI主线程发送消息
  3. Android(安卓)根文件系统启动分析
  4. Android(安卓)屏幕截图 代码
  5. 初体验Android的两个小不爽
  6. 猫猫学iOS之二维码学习,快速生成二维码
  7. Android——智能指针
  8. Android环境配置 AndroidStudio安装教程
  9. Android下的实现对本地指定和筛选文件的
  10. android staticlayout使用讲解