17 对话框


package com.szy.dialogs;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity
{
private static final int MAX_PROGRESS = 100;
private final static int SIMPLEALERTDIALOG = 1;
private final static int LISTALERTDIALOG = 2;
private final static int SINGLECHOICEALERTDIALOG = 3;
private final static int PROGRESSTDIALOG = 4;
private final static int CUSTOMALERTDIALOG = 5;

private ProgressDialog progressDialog;
private Handler progressHandler;
private int progress;
private AlertDialog alert;

private Button simpleAlertDialog;
private Button listAlertDialog;
private Button singleChoiceAlertDialog;
private Button progressAlertDialog;
private Button customAlertDialog;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 简单警告对话框
simpleAlertDialog = (Button) findViewById(R.id.simpleAlertDialog);
simpleAlertDialog.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
showDialog(SIMPLEALERTDIALOG);
}
});

// 列表对话框
listAlertDialog = (Button) findViewById(R.id.listAlertDialog);
listAlertDialog.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{

showDialog(LISTALERTDIALOG);
}
});

// 单选对话框
singleChoiceAlertDialog = (Button) findViewById(R.id.singleChoiceAlertDialog);
singleChoiceAlertDialog.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
showDialog(SINGLECHOICEALERTDIALOG);
}
});

// 进度条
progressAlertDialog = (Button) findViewById(R.id.progressAlertDialog);
progressAlertDialog.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
showDialog(PROGRESSTDIALOG);
progress = 0;
progressDialog.setProgress(0);
progressHandler.sendEmptyMessage(0);
}
});

// 自定义对话框
customAlertDialog = (Button) findViewById(R.id.customAlertDialog);
customAlertDialog.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
showDialog(CUSTOMALERTDIALOG);
}
});

// 进度条Handler
progressHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
if (progress >= MAX_PROGRESS)
{
progressDialog.dismiss();
}
else
{
progress++;
progressDialog.setProgress(progress);
progressHandler.sendEmptyMessageDelayed(0, 100);
}
}
};
}

@Override
protected Dialog onCreateDialog(int id)
{
Log.i("MainActivity","@@@@@@@@@@@@@");
final CharSequence[] items =
{ "红色", "黄色", "蓝色" };
AlertDialog.Builder builder = null;
builder = new AlertDialog.Builder(this);
switch (id)
{
case SIMPLEALERTDIALOG:
builder.setMessage("你确定要退出本软件吗?");
builder.setCancelable(false);// 返回键是否可以关闭对话框
builder.setPositiveButton("是", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
MainActivity.this.finish();
}
});
builder.setNegativeButton("否", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
return builder.create();
case LISTALERTDIALOG:
builder.setTitle("请选中一种颜色");
builder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
return builder.create();
case SINGLECHOICEALERTDIALOG:

builder.setTitle("请选中一种颜色");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
if (null!=alert)
{
alert.dismiss();
}
}
});
alert = builder.create();
return alert;
case PROGRESSTDIALOG:
progressDialog = new ProgressDialog(this);
// progressDialog.setIconAttribute(android.R.attr.alertDialogIcon);
progressDialog.setTitle("进度条");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(MAX_PROGRESS);
progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{

}
});
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{

}
});
return progressDialog;
case CUSTOMALERTDIALOG:
LayoutInflater factory = LayoutInflater.from(this);
final View textView = factory.inflate(R.layout.custom, null);
builder.setIcon(R.drawable.qq);
builder.setTitle("自定义对话框");
builder.setView(textView);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{

}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{

}
});
return builder.create();
default:
break;
}
return null;
}
}

http://www.oschina.net/question/54100_32486

7中对话框样式

17 对话框,码迷,mamicode.com

时间: 2024-08-09 02:18:09

17 对话框的相关文章

DuiVision开发教程(17)-对话框

DuiVision的对话框类是CDlgBase. 代码中如果需要创建一个对话框,一般建议使用DuiSystem类中封装的若干对话框相关的函数来操作,包括创建对话框.删除对话框.根据对话框名获取对话框指针.显示通用对话框. 对话框的属性如下: 属性名 类型 说明 width 数字 窗口宽度 height 数字 窗口高度 resize 0|1 1表示窗口可以改变大小 frame 字符串 窗口的frame层图片,frame层是一个可选的半透明Alpha图片层,一般设置的这个图片是用于和背景图片进行Al

MFC 注册表编程

记录点滴. 对话框部分程序: 1 // RegeditDlg.h : 头文件 2 // 3 4 #pragma once 5 #include "afxwin.h" 6 7 // 注册表监控线程函数 8 static DWORD WINAPI ThreadFunc(); 9 10 // CRegeditDlg 对话框 11 class CRegeditDlg : public CDialogEx 12 { 13 // 构造 14 public: 15 CRegeditDlg(CWnd*

<模电学习1>Multisim 12.0 搭建并仿真51单片机最小系统

环境: 系统环境: win7 64位 软件平台:Multisim 12.0 目的: 刚毕业,但是模电知识也忘得差不多了,加之自己想搞搞硬件设计,如果只是看模电书,不实践,还是终觉浅.当做兴趣一样学学模电,仿真仿真.Multisim的MCU少,就拿51来练练手,搭建51单片机仿真系统,配合着记录一下书本的知识. 概述: 最后使用Multisim 12.0搭建出来的最小系统为图1-1所示,通过编写程序可以使LED1循环闪烁. 图1-1 正常来说,51单片机最小系统一般包括单片机.晶振电路.复位电路,

<模拟电子学习1>Multisim 12.0 结构和仿真51最小的单芯片系统

周围环境: 系统环境: win7 64位置 软件平台:Multisim 12.0 目的: 刚毕业,可是模电知识也忘得差点儿相同了,加之自己想搞搞硬件设计.假设仅仅是看模电书.不实践,还是终觉浅.当做兴趣一样学学模电,仿真仿真. Multisim的MCU少,就拿51来练练手.搭建51单片机仿真系统,配合着记录一下书本的知识. 概述: 最后使用Multisim 12.0搭建出来的最小系统为图1-1所看到的,通过编敲代码能够使LED1循环闪烁. 图1-1 正常来说.51单片机最小系统一般包含单片机.晶

使用CSS3制图

参考资料:http://blog.csdn.net/fense_520/article/details/37892507 本文非转载.为个人原创,转载请先联系博主,谢谢~ 准备: <!DOCTYPE html> <head> <meta charset="UTF-8"> <title>- UED - </title> <style type="text/css" src="css/style

AnimeGAN输出日志

D:\MyFiles\LearnFiles\Code\Python\AnimeGAN\AnimeGAN>python main.py --phase train --dataset Hayao --epoch 1 --init_epoch 1D:\Users\feng_\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning:

基于MVC+EasyUI的Web开发框架经验总结(17)--布局和对话框自动适应大小的处理

在我自己的<Web开发框架>中,用了很多年的EasyUI,最新版本EasyUI为1.4.5,随着版本的更新,其很多功能得到了很大的完善和提高,同时也扩展了一些新的功能,以前在布局和对话框弹出层的自动适应大小的问题,也在最近的一些版本得到了解决,本文在迁移到最新EasyUI版本的时候,总结了一些经验,希望对大家使用这个强大的Web界面组件有所帮助. 1.Web主界面的布局调整 上面的布局是顶部内容+一级菜单.左边菜单,右边主内容为页面内容,页面内容是变化的内容,其他部分为不变的,这样的布局代码如

第17课 对话框及其类型

1. 对话框的概念 (1)概念 ①对话框是与用户进行简短交互的顶层窗口 ②QDialog是Qt中所有对话框窗口的基类 ③QDialog继承于QWidget是一种容器类型的组件 (2)QDialog的意义 ①QDialog作为一种专用的交互窗口而存在 ②QDialog不能作为子部件嵌入其它容器中 ③QDialog是定制了窗口式样的特殊的QWidget [编程实验]QDialog和QWidget的区别 #include <QApplication> #include <QWidget>

【Qt5开发及实例】17、一个对话框的坐标参数显示

一个对话框的坐标参数显示 介绍 这个是为了得到对话框的长宽,各个点的坐标,相对坐标,相对父窗口的坐标,相对在桌面的坐标 代码 geometry.h /** * 书本:[Qt5开发及实例] * 功能:显示对话框的坐标信息,参数信息 * 文件:geometry.cpp * 时间:2015年1月20日20:19:35 * 作者:cutter_point */ #ifndef GEOMETRY_H #define GEOMETRY_H #include <QDialog> #include <Q