zoukankan      html  css  js  c++  java
  • 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>



  • 相关阅读:
    I can do more…
    在希望的田野上
    卓越管理培训笔记
    Python 学习小计
    谈谈“直抒己见”
    [更新]关于博客园不支持RSS全文输出的解决方案
    效率生活二三事
    个人阅读解决方案
    Oracle函数sys_connect_by_path 详解
    基础班-模板配置
  • 原文地址:https://www.cnblogs.com/jiayonghua/p/2276962.html
Copyright © 2011-2022 走看看