AlertDialog 对话框属性学习笔记
2012-07-12 12:38
330 查看
JAVA 代码:
public class AlertdialogActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) this.findViewById(R.id.button1);//对象
button.setOnClickListener(new myclick());
}
class myclick implements OnClickListener{
@Override
public void onClick(View v) {
showDialog(0);//显示对话框,系统将会自动调用onCreateDialog;不需要操纵
}
}
@Override
protected Dialog onCreateDialog(int id) {//创建对话框样式
// TODO Auto-generated method stub
AlertDialog.Builder builder =new AlertDialog.Builder(this);//实例化对象
builder.setIcon(R.drawable.aaa);
builder.setTitle("这是一个问题:");
builder.setMessage("你是男生吗?");
myclick1 thi = new myclick1();
builder.setPositiveButton("是<YES>", thi);
builder.setNegativeButton("取消<CANCEL>", thi);
builder.setNeutralButton("否<NO>",thi);
AlertDialog dialog = builder.create();//创建对话框
return dialog;
}
class myclick1 implements DialogInterface.OnClickListener{
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch(which){
case Dialog.BUTTON_POSITIVE:
System.out.println("纯爷们");
break;
case Dialog.BUTTON_NEGATIVE:
System.out.println("女孩");
break;
case Dialog.BUTTON_NEUTRAL:
System.out.println("不知道");
break;
default:
break;
main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/b11"
android:id="@+id/aad"
>
<Button
android:text="显示对话框"
android:layout_gravity="center"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></Button>
</LinearLayout>
相关文章推荐
- Android笔记:Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android应用开发学习笔记之AlertDialog对话框
- android 开发零起步学习笔记(二十三): Android 对话框AlertDialog和AlertDialog.Builder两者的区别
- Android酱油笔记之关闭AlertDialog.Builder对话框
- javascript学习笔记(十六) 系统对话框(alert、confirm、prompt)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog) 推荐
- Android基础之AlertDialog(对话框)的学习
- 20151215jquery学习笔记--jqueryUI --dialog(对话框)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- swing 学习笔记六(对话框Dialog )
- swing 学习笔记六(对话框Dialog )
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- IOS开发学习笔记-(2)键盘控制,键盘类型设置,alert 对话框
- 弹出对话框AlertDialog.Builder使用笔记
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- android基础学习(6)-------AlertDialog.Builder提示对话框
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)2010-06-16 18:17:21