在图形界面之中,对话框也是人机交互的一种重要的形式,程序可以通过对话框对用户进行一些信息的提示,而

用户也可以通过对话框和程序进行一些简单的交互操作。

在Android的开发之中,所有的对话框都是从android.app.Dialog类继承而来的。

Alert表示的是一个警告的含义,所以AlertDialog表示是的一个警告的概念,主要的功能是产生一条警告信息。

AlertDialog是Dialog的直接子类,所有可以使用Dialog类的各个操作方法,但是这个类的构造方法全部

使用了Protected关键字定义,所以这个关键字定义的权限特点:本类、同一包的类,不同包的子类可以

访问,所以也就意味着AlertDialog类的构造方法被隐藏了。

如果要想创建AlertDialog对话框,那么就必须使用AlertDialogBuilder类完成,而通过这个类的名称

就可以清楚的发现它是一个专门用于对话框的创建类。

在main.xml中

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal" >

<TextView

android:id="@+id/mytext"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="北海银滩" />

<Button

android:id="@+id/mybut"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="删除"/>

</LinearLayout>

在MyDialogDemo.java程序中

package com.tarena.dialog;

import android.app.Activity;

import android.app.AlertDialog;

import android.app.Dialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MyDialogDemo extends Activity {

private Button mybut = null;  //定义按钮

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main);  //调用布局管理器

this.mybut = (Button) super.findViewById(R.id.mybut);  //取得按钮

this.mybut.setOnClickListener(new OnClickListenerImpl());  //设置事件类

}

private class OnClickListenerImpl implements OnClickListener{

public void onClick(View v) {

Dialog dialog = new AlertDialog.Builder(MyDialogDemo.this)

.setTitle("删除信息?")  // 创建标题

.setMessage("您确定要删除这条信息吗?")    //表示对话框的内容

.setIcon(R.drawable.ic_launcher) //设置LOGO

.setPositiveButton("删除", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

}).setNeutralButton("查看详情", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

}).setNegativeButton("取消", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

}).create();  //创建对话框

dialog.show();  //显示对话框

}

}

}

android 删除的警告对话框的更多相关文章

  1. Android中的AlertDialog使用示例一(警告对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  2. Android开发学习之对话框浅析

    对话框式程序运行中弹出的窗口.Android系统中有四种默认的对话框:警告对话框AlertDialog.进度对话框ProgressDialog.日期选择对话框DatePickerDialog以及时间选 ...

  3. android 开发AlertDialog.builder对话框的实现

    AndroidAPI提供了Dialog对话框控件,但google明确指出不建议开发者只是使用Dialog来创建对话框,而应该自定义对话框或者使用API中提供的Dialog的子类,如AlertDialo ...

  4. Android 自定义AlertDialog退出对话框

    Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...

  5. android学习笔记16——对话框

    android支持丰富的对话框,常用4中对话框: 1.AlertDialog: 2.ProgressDialog:进度对话框,这个对话框只是对进度条的封装 3.DatePickerDialog:日期选 ...

  6. matlab学习------------普通dialog对话框,错误对话框errordlg,警告对话框warndlg

    Dialog对话框 语法: h = dialog('PropertyName',PropertyValue,...) 对话框的默认属性 WindowStyle的值:   {normal} | moda ...

  7. IOS开发之XCode学习014:警告对话框和等待提示器

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.警告对话框和等待提示器的概念 2.警告对话框 ...

  8. Android学习:AlertDialog对话框

    AlertDialog可以生成各种内容的对话框,它生成的对话框包含4个区域:图标区,标题区,内容区,按钮区 <?xml version="1.0" encoding=&quo ...

  9. Android下setLatestEventInfo警告、Handler警告、SimpleDateFormat警告

    正 文: 今天飘易在做Android 4.4.2下的APP开发时,使用了Notification下的setLatestEventInfo()方法时,Eclipse却提示:“ 不建议使用类型 Notif ...

随机推荐

  1. 使用Javascript 实现类

    /** * 人类 * @author rubekid */ function Person(options){ //私有属性 var _name; //姓名 var _age; //年龄 /** * ...

  2. spring-qualifier解释

    如果一个class有两个对应的beanId,在Autowired的时候,必须指定Qualifier("指定其中一个beanId"). org.springframework.bea ...

  3. java克隆总结

    对象clone,注意基本类型和指针类型.

  4. 解决Cacti监控图像断断续续问题

    最近cacti的图像全都是断断续续.新加的设备,图像也是这样,查看cacti 的log发现大量下面类似的错误信息:04/12/2011 03:54:37 PM - SPINE: Poller[0] H ...

  5. java.lang.NumberFormatException: empty String 错误

    原因:前台获取的字符串,后台类型转换,与之对应的实体类中却是Integer类型,所以会报错. 排错情况:1.先检查数据库与实体类中的类型是否一致 2.检查类型转换代码,如果需要加入异常处理

  6. Undefined symbols for architecture x86_64:

    真机运行正常, 但要在模拟器运行的时候, 编译就报错了: 解决方法: 1.将Build Settings的Architectures修改为arm7 armv7s.Xcode7默认是加上arm64的,但 ...

  7. Css Div半透明

    用CSS控制外层DIV不透明,而内层DIV透明,这样实现的效果是意想不到的,还不错吧,其实代码也是很简单的,也很好理解,主要是用了CSS的滤镜. <html xmlns="http:/ ...

  8. Web 端 js 导出csv文件(使用a标签)

    前言 导出文件,使用最多的方式还是服务器端来处理.比如jsp 中使用response 的方式. 但是,有时候可能就想使用web 前端是否也可以把页面上的内容导出来呢? 比如说,导出页面的一个表格. 这 ...

  9. smarty 自定义函数

    自定义函数:<{方法名称}> 在lib/plugins中新建文件,命名方式是固定的:function.方法名称.php 或者 block.方法名称.php 1.<{literal}& ...

  10. PHP判断文章里是否有图片

    用preg_match来检查内容里是否有匹配的“<img”,其实我们还用preg_match来判断很多东西,比如邮箱地址里是否有“@”等,下面用一小段代码来演示具体用法. $content=&q ...