android例子分析-1
16lz
2021-01-23
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中NDK的使用方法
- android:编写属性动画程序(旋转,缩放,淡出淡入)
- Android的window类的常用方法
- Android 监听程序的安装、卸载、替换
- Android获取开机启动程序列表
- Android记事本程序源码
- Android 拨打webView 里面的电话号码的方法
- android 在线视频播放器实现方法
- Android下各文件方法获取的路径