AlertDialog对话框

效果图:

Test1Activity.java

 1 package xiacl.test;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.view.View;
 6 import android.widget.Button;
 7 
 8 import android.app.AlertDialog;
 9 import android.content.DialogInterface;
10 
11 public class Test1Activity extends Activity {
12     private Button mButton1;
13     /** Called when the activity is first created. */
14     @Override
15     public void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.main);
18         
19         mButton1=(Button)findViewById(R.id.myButton1);
20         mButton1.setOnClickListener(new Button.OnClickListener()
21         {
22 
23             @Override
24             public void onClick(View v) {
25                 // TODO Auto-generated method stub
26                 /*这里就是设置弹出对话框的地方*/
27                 new AlertDialog.Builder(Test1Activity.this)
28                 .setTitle(R.string.app_about)
29                 .setMessage(R.string.app_about_msg)
30                 .setPositiveButton
31                 (
32                         R.string.str_ok, 
33                         new DialogInterface.OnClickListener() {
34                             
35                             @Override
36                             public void onClick(DialogInterface dialog, int which) {
37                                 // TODO Auto-generated method stub
38                                 /*在这里设计当对话按钮单击之后要运行的事件*/
39                                 finish();//离开程序
40                             }
41                         })
42                 .show();                
43             }           
44         });
45     }
46 }

 

 posted on 2012-06-10 18:50  xiacl  阅读(257)  评论(0编辑  收藏  举报