Android中常用的对话框总结
来源:互联网 发布:pic下载软件 编辑:程序博客网 时间:2024/05/17 22:48
把常用的对话框记一下,方便以后查用
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <Button android:onClick="click1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="确定取消对话框" /> <Button android:onClick="click2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="单选对话框" /> <Button android:onClick="click3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="多选对话框" /> <Button android:onClick="click4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="进度条对话框" /></LinearLayout >
代码实现
package com.wzw.dialog;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.app.ProgressDialog;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.content.DialogInterface.OnMultiChoiceClickListener;import android.os.Bundle;import android.view.View;import android.widget.Toast;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}/** * 确定取消对话框 * @param v */public void click1(View v){AlertDialog.Builder builder=new Builder(this);builder.setTitle("我是标题");builder.setMessage("我是提示信息");builder.setPositiveButton("确定", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Toast.makeText(getApplicationContext(), "确定被点击啦", 0).show();}});builder.setNegativeButton("取消", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//Toast.makeText(getApplicationContext(), "取消被点击啦", 0).show();// 什么都不写,默认的是关闭对话框}});builder.create().show();}/** * 单选对话框 * @param v */public void click2(View v){AlertDialog.Builder builder=new Builder(this);builder.setTitle("我是标题");final String items[]={"男","女","屌丝"};builder.setSingleChoiceItems(items, 2, new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Toast.makeText(getApplicationContext(), "性别是"+items[which], 0).show();dialog.dismiss();}});builder.create().show();}/** * 多选对话框 * @param v */public void click3(View v){AlertDialog.Builder builder=new Builder(this);builder.setTitle("我是标题");final String[] items={"苹果","香蕉","栗子","西瓜"};final boolean[] result=new boolean[]{true,false,true,false};builder.setMultiChoiceItems(items, result, new OnMultiChoiceClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which, boolean isChecked) {// TODO Auto-generated method stubToast.makeText(getApplicationContext(), items[which]+isChecked, 0).show();result[which]=isChecked;}});builder.setPositiveButton("提交", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {StringBuffer sb=new StringBuffer();for (int i = 0; i < result.length; i++) {if(result[i]){sb.append(items[i]+"--");}}Toast.makeText(getApplicationContext(), "您的选择"+sb.toString(), 0).show();}});builder.create().show();}public void click4(View v){ProgressDialog pd=new ProgressDialog(this);pd.setTitle("提示信息");pd.setMessage("正在加载数据,请稍等");pd.show();}}
0 0
- Android中常用的对话框总结
- Qt中常用的对话框总结QDialog
- Android中常用对话框
- Android中常用的对话框的创建
- 【实战】android中几个常用的对话框
- 常用的Android对话框
- 常用的android对话框
- Android 中常用对话框使用
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android提示对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 小爬虫-一个网页上的.jpg图片下载下来
- hdu 1025
- poj1827A Bunch Of Monsters(贪心)
- 机器学习
- 第十一次新生排位赛
- Android中常用的对话框总结
- [网站] 三星开源软件中心
- CSS布局
- python Win7下搭建
- 事物的本质,到底离我们有多远?
- 截取字符串“20|http://www.baidu.com”中 “|” 前面和后面的字符串,并输出。将“文艺青年”改成“213青年”。
- BOJ 488 小妹妹个数
- C++基础——继承与派生
- hdu2102