`
baobaocao521
  • 浏览: 29222 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

android例子分析-1

阅读更多
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) */
  };
  
}

 

  • 大小: 17.6 KB
分享到:
评论
1 楼 xiamizy 2010-07-23  
好膜拜你。感觉你好猛啊

相关推荐

Global site tag (gtag.js) - Google Analytics