六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 44|回复: 0

android例子分析-1

[复制链接]

升级  10.67%

14

主题

14

主题

14

主题

秀才

Rank: 2

积分
66
 楼主| 发表于 2013-1-15 02:26:13 | 显示全部楼层 |阅读模式
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) */  };  } 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表