Android 开发笔记___alertDialog

 1 public class AlertActivity extends AppCompatActivity implements OnClickListener {
 2 
 3     private TextView tv_alert;
 4 
 5     @Override
 6     protected void onCreate(Bundle savedInstanceState) {
 7         super.onCreate(savedInstanceState);
 8         setContentView(R.layout.activity_alert);
 9         findViewById(R.id.btn_alert).setOnClickListener(this);
10         tv_alert = (TextView) findViewById(R.id.tv_alert);
11     }
12 
13     @Override
14     public void onClick(View v) {
15         if (v.getId() == R.id.btn_alert) {
16             AlertDialog.Builder builder = new AlertDialog.Builder(this);
17             builder.setTitle("尊敬的用户");
18             builder.setMessage("你真的要卸载我吗?");
19             builder.setPositiveButton("残忍卸载", new DialogInterface.OnClickListener() {
20                 @Override
21                 public void onClick(DialogInterface dialog, int which) {
22                     tv_alert.setText("虽然依依不舍,还是只能离开了");
23                 }
24             });
25             builder.setNegativeButton("我再想想", new DialogInterface.OnClickListener() {
26                 @Override
27                 public void onClick(DialogInterface dialog, int which) {
28                     tv_alert.setText("让我再陪你三百六十五个日夜");
29                 }
30             });
31             AlertDialog alert = builder.create();
32             alert.show();
33         }
34     }
35 
36 }

 

posted @ 2017-07-04 16:06  alm  阅读(215)  评论(0编辑  收藏  举报