android 33 对话框控件
对话框控件:最多3个按钮。
mainActivity.java
package com.sxt.day05_09; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListener();
} private void setListener() {
setStandardDialogClickListener();
setItemsDialogClickListener();
setCustomDialogClickListener();
} //自定义对话框
private void setCustomDialogClickListener() {
findViewById(R.id.btnCustomDialog).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//将custom_dialog.xml解析为一个View类型的java对象
View layout = View.inflate(MainActivity.this, R.layout.custom_dialog, null);
final EditText etAddrss=(EditText) layout.findViewById(R.id.etAddress);
AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);//Builder是内部类
builder.setTitle("输入地址的对话框")//setTitle()返回builder对象(builder对象的地址),所以可以继续用点调用其他方法,
.setView(layout)//添加自定义布局,替换掉setMessage()
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String address=etAddrss.getText().toString();//内部类调用外部的方法的变量要是final类型
Log.i("main",address);
}
});
AlertDialog dialog = builder.create();//create最终创建对话框
dialog.show();//显示出来
}
});
} //列表类型的对话框
private void setItemsDialogClickListener() {
findViewById(R.id.btnItemsDialog).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//真正创建对话框不是AlertDialog,而是这个类的内部类Builder,
AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
builder.setItems(new String[]{"增加数据","删除数据","修改数据"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {//dialog是当前操作的AlertDialog对象,
switch (which) {
case 0:
Toast.makeText(MainActivity.this, "执行增加数据的操作", 3000).show();
break;
case 1:
Toast.makeText(MainActivity.this, "执行删除数据的操作", 3000).show();
break;
case 2:
Toast.makeText(MainActivity.this, "执行修改数据的操作", 3000).show();
break;
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
} //标准对话框
private void setStandardDialogClickListener() {
findViewById(R.id.btnStandardDialog).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//创建对话框的Builder对象,Builder是AlertDialog的内部类
AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
builder.setTitle("退出考试窗口")
.setMessage("退出考试吗?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {//setPositiveButton创建肯定的按钮,按钮文本是"确定",点击按钮的监听器是DialogInterface.OnClickListener
//OnClickListener是DialogInterface的内部接口,
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("main","退出考试");
}
}).setNegativeButton("放弃", new DialogInterface.OnClickListener() {////setNegativeButton创建否定的按钮,按钮的文本和监听器
//如果不添加监听器,则仅仅关闭对话框没有动作。
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("main","继续考试");
}
});
AlertDialog dialog = builder.create();//create最终创建对话框
dialog.show();//显示出来
}
});
} }
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <Button
android:id="@+id/btnStandardDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="标准对话框" />
<Button
android:id="@+id/btnItemsDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="列表对话框" />
<Button
android:id="@+id/btnCustomDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义对话框" /> </LinearLayout>
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入地址"/>
<EditText
android:id="@+id/etAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
android 33 对话框控件的更多相关文章
- Android 中常见控件的介绍和使用
1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...
- 【转】Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用
Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用 分类: Android UI ...
- 【风马一族_Android】第4章Android常用基本控件
第4章Android常用基本控件 控件是Android用户界面中的一个个组成元素,在介绍它们之前,读者必须了解所有控件的父类View(视图),它好比一个盛放控件的容器. 4.1View类概述 对于一个 ...
- Android 一个日历控件的实现代码
转载 2017-05-19 作者:Othershe 我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...
- Android笔记---常用控件以及用法
这篇文章主要记录下Android的常用控件以及使用的方法,Android 给我们提供了大量的UI控件,合理地使用这些控件就可以非常轻松地编写出相当不错的界面,这些是Android学习的基础,没有什么业 ...
- CAD控件,CAD插件使用教程:Android开发使用控件--开发环境的搭建
Android开发使用控件入门--环境搭建 2014-12-24 09:57 14人阅读 评论(0) 收藏 编辑 删除 CAD控件.CAD三维控件,手机 ...
- Android开发使用控件入门--环境搭建
Android开发使用控件入门--环境搭建 软件名称(,梦,,想.CAD ,控件) 1. 环境搭建: 3 1.1. 安装Eclipse 3 1.2. 下载JDK 3 1.3. 下载Android S ...
- winform对话框控件、打印控件
对话框控件: ColorDialog:颜色选择对话框,让用户自行选择一种颜色,使用方法类似FontDialog FontDialog:字体选择对话框,让用户自行选择一种字体(也可以选择字体颜色,需要在 ...
- Android中ListView控件的使用
Android中ListView控件的使用 ListView展示数据的原理 在Android中,其实ListView就相当于web中的jsp,Adapter是适配器,它就相当于web中的Servlet ...
随机推荐
- Object之克隆对象clone 和__clone()函数
在前面的PHP面向对象之对象和引用,"$b=$a"的方式复制对象传递的是对象的地址,而不是传递对象的值(内容),我们可以通过克隆对象来实现对对象的内容和引用的复制 使用传址引用的方 ...
- Ubuntu启动错误Checking Battery State的处理
一.问题描述 二.处理方法 方法一: 按下 ctrl + alt + F1,进入终端,使用管理员权限执行下列代码 sudo rm /etc/X11/xorg.conf sudo reboot 方法二: ...
- 初学socket,c语言写的简单局域网聊天
在客户端所在的目录新建一个IP.bwj的文件,写上服务端的IP,不要带空格,保存.双方都打开一个客户端和一个服务端就可以聊天了,(可以写自己的IP,自己跟自己聊..)没有第三方服务器,服务端所在的电脑 ...
- Label设置行间距--b
内容摘要 UILabel显示多行文本 UILabel设置行间距 解决单行文本 & 多行文本显示的问题 场景描述 众所周知,UILabel显示多行的话,默认行间距为0,但实际开发中,如果显示多行 ...
- 欧拉计划 NO05 ps:4题想过,好做,但麻烦,有时间补充,这题也不难!
问题重述: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without an ...
- “未能加载文件或程序集file:///E:/MoneySet.dll或它的某一个依赖项,试图加载格式不正确的程序,行203,位置5. 文件:MReportSet.resx”,
http://bbs.csdn.net/topics/390334265 1.右键卸载项目2.右键选择编辑工程文件,在打开的文件的最后一行</project>之前加以下内容: <Pr ...
- JVM相关参数配置和问题诊断<转>
原文连接:http://blog.csdn.net/chjttony/article/details/6240457 1.Websphere JVM相关问题诊断: 由JVM引起的Websphere问题 ...
- Haskell缩进规则
Haskell也是使用缩进来表示一个表达式或者块延伸的范围的,这点与Python类似.Haskell的缩进规则简单总结起来只用下面三条: 1. 源文件中第一个顶级的定义或者声明的缩进,定义了该文 ...
- Android 中的MVC与数据流动
今天看了一个Android的Training生命周期转换的例子,顿觉得他的设计非常巧妙,我的分析如下: 1.在com.example.android.lifecycle包中有: 3个正常的全屏acti ...
- bzoj2734
非常巧妙地题目对于一个数x列出这样的矩阵x 2x 4x 8x ……3x 6x 12x 24x ………………………………不难方案数就是求取数不相邻的方案数考虑矩阵宽不超过logn,所以可以用状压dp解决 ...