• Android


    MainActivity.java

     1 package com.example.zc.alertdialog;
     2 
     3 import android.content.DialogInterface;
     4 import android.support.v7.app.AlertDialog;
     5 import android.support.v7.app.AppCompatActivity;
     6 import android.os.Bundle;
     7 import android.view.View;
     8 import android.widget.Button;
     9 
    10 public class MainActivity extends AppCompatActivity {
    11 
    12     private Button mButton;
    13     @Override
    14     protected void onCreate(Bundle savedInstanceState)
    15     {
    16         super.onCreate(savedInstanceState);
    17         setContentView(R.layout.activity_main);
    18 
    19 
    20         mButton = (Button) findViewById(R.id.button);//引用已生成的组件
    21         mButton.setOnClickListener(
    22                 new View.OnClickListener()
    23                 {
    24                     @Override
    25                     public void onClick(View v)
    26                     {
    27                         //Alert1();
    28                         //Alert2();
    29                         Alert3();
    30                     }
    31                 }
    32         );
    33 
    34 
    35 
    36     }
    37 
    38     public void Alert1()
    39     {
    40         new AlertDialog.Builder(this)
    41                 .setTitle("Android 提示")
    42                 .setMessage("这是一个提示,请确定")
    43                 .show();
    44     }
    45     public void Alert2()
    46     {
    47         new AlertDialog.Builder(this)
    48                 .setMessage("这是第二个提示")
    49                 .setPositiveButton("确定",
    50                         new DialogInterface.OnClickListener(){
    51                             public void onClick(DialogInterface dialoginterface, int i){
    52                                 //按钮事件
    53                             }
    54                         })
    55                 .show();
    56     }
    57     public void Alert3()
    58     {
    59         new AlertDialog.Builder(this)
    60                 .setTitle("提示")
    61                 .setMessage("确定退出?")
    62                 //.setIcon(R.drawable.quit)
    63                 .setPositiveButton("确定", new DialogInterface.OnClickListener() {
    64                     public void onClick(DialogInterface dialog, int whichButton) {
    65                         setResult(RESULT_OK);//确定按钮事件
    66                         finish();
    67                     }
    68                 })
    69                 .setNegativeButton("取消", new DialogInterface.OnClickListener() {
    70                     public void onClick(DialogInterface dialog, int whichButton) {
    71                         //取消按钮事件
    72                     }
    73                 })
    74                 .show();
    75     }
    76 
    77 
    78 
    79 }

    activity_main.xml

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2               android:layout_width="match_parent"
     3               android:layout_height="match_parent"
     4               android:orientation="vertical"
     5     >
     6 
     7     <Button
     8         android:id="@+id/button"
     9         android:layout_width="wrap_content"
    10         android:layout_height="wrap_content"
    11         android:text="hello"
    12         android:layout_gravity="center"
    13         />
    14 
    15 </LinearLayout>

  • 相关阅读:
    1503: [NOI2004]郁闷的出纳员
    2049: [Sdoi2008]Cave 洞穴勘测
    2301: [HAOI2011]Problem b
    BZOJ 1923: [Sdoi2010]外星千足虫
    BZOJ 2115: [Wc2011] Xor
    POJ 1830 开关问题
    欧拉函数基础
    BZOJ 2186 沙拉公主的困惑
    POJ 1845
    逆元基础知识整理
  • 原文地址:https://www.cnblogs.com/1228073191Blog/p/7686815.html
Copyright © 2020-2023  润新知