• Android AlertDialog 实例


     1 package com.turboradio.googlesdk;
    2
    3 import android.app.Activity;
    4 import android.app.AlertDialog;
    5 import android.content.DialogInterface;
    6 import android.os.Bundle;
    7 import android.view.View;
    8
    9 public class Ex_4_26 extends Activity {
    10
    11 @Override
    12 protected void onCreate(Bundle savedInstanceState) {
    13 super.onCreate(savedInstanceState);
    14 setContentView(R.layout.ex_4_26);
    15 }
    16 /**离开程序**/
    17 public void leave(View v){
    18 new AlertDialog.Builder(Ex_4_26.this)
    19 /**设置标题**/
    20 .setTitle("重要")
    21 /**设置icon**/
    22 .setIcon(android.R.drawable.alert_dark_frame)
    23 /**设置内容**/
    24 .setMessage("你确定要关闭吗?")
    25 .setNegativeButton("取消", new DialogInterface.OnClickListener(){
    26
    27 public void onClick(DialogInterface dialog, int which) {
    28 // TODO Auto-generated method stub
    29
    30 }}).setPositiveButton("确定", new DialogInterface.OnClickListener(){
    31
    32 public void onClick(DialogInterface dialog, int which) {
    33 /**关闭窗口**/
    34 finish();
    35
    36 }}).show();
    37
    38 }
    39 }

    ex_4_26.xml

     1 <?xml version="1.0" encoding="utf-8"?>
    2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3 android:layout_width="fill_parent"
    4 android:layout_height="fill_parent"
    5 android:orientation="vertical" >
    6 <Button
    7 android:layout_width="wrap_content"
    8 android:layout_height="wrap_content"
    9 android:text="按我离开"
    10 android:onClick="leave"
    11 />
    12 </LinearLayout>



  • 相关阅读:
    MySQL-MMM方案
    MySQL双主复制
    MySQL主从复制
    Keepalived实现高可用
    CentOS7.2 部署Haproxy 1.7.2
    博客园写随笔时用数学公式
    Java中有三种移位运算符
    VS Code配置C/C++环境
    Visual Studio Code 如何编写运行 C、C++ 程序?
    头一次知道“原地算法”?!
  • 原文地址:https://www.cnblogs.com/jiayonghua/p/2276962.html
Copyright © 2020-2023  润新知