其他分享
首页 > 其他分享> > Android--AlertDialog(1)

Android--AlertDialog(1)

作者:互联网

 1 public class MainActivity extends AppCompatActivity implements View.OnClickListener{
 2 
 3     private TextView text_out;
 4     
 5     @Override
 6     protected void onCreate(Bundle savedInstanceState) {
 7         super.onCreate(savedInstanceState);
 8         setContentView(R.layout.activity_main_activity);
 9 
10         initView();
11        
12     }
13 
14     private void initView() {
15         text_out=findViewById(R.id.text_out);
16         text_out.setOnClickListener(this);
17     }
18 
19     @Override
20     public void onClick(View view){
21         AlertDialog.Builder builder =new AlertDialog.Builder(this);
22         builder.setTitle("退出");
23         builder.setMessage("确定要退出吗?");
24         builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
25             @Override
26             public void onClick(DialogInterface dialogInterface, int i) {
27                 // 关闭对话框
28                 dialogInterface.dismiss();
29                // 退出程序
30                 VideoMonitor.this.finish();
31             }
32         });
33         builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
34             @Override
35             public void onClick(DialogInterface dialogInterface, int i) {
36             dialogInterface.dismiss();
37             }
38         });
39         AlertDialog adialog= builder.create();
40         adialog.show();
41     }  
42 }        

 

标签:--,text,void,dialogInterface,AlertDialog,Android,builder,out
来源: https://www.cnblogs.com/wwll2020/p/15137930.html