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

更多相关文章

  1. Android组件通信
  2. Android中NDK的使用方法
  3. Android(安卓)高德地图 定位+围栏
  4. Android实现各种对话框的变体
  5. Android实现各种对话框的变体
  6. Android(安卓)ProgressBar 进度条颜色和背景颜色
  7. android 性能优化
  8. android MediaRecorder 视频录制
  9. Android的window类的常用方法

随机推荐

  1. Android(安卓)MapView 申请apiKey
  2. android,NativeActivity使用
  3. Android各种键盘挡住输入框解决办法
  4. Android中Fragment讲解及Fragment静态的
  5. Android(安卓)logcat内核信息
  6. 面试题八:事件分发机制
  7. 【Android(安卓)系统开发】使用 Source I
  8. 在代码中设置RelativeLayout布局中标签的
  9. android handler
  10. IDA调试Android(安卓)so文件