Andriod 对话框

在Activity中可以调用showDialog()来显示一个对话框,覆盖Activity的onCreateDialog方法,在这个方法中创建对话框,返回一个Dialog对象。

1.最简单的对话框

  1. AlertDialog.Builder b=new  AlertDialog.Builder(this);  
  2. b.setTitle("简单的");  
  3.             b.setMessage("this is a simple dialog");  
  4.             b.setPositiveButton("是"new DialogInterface.OnClickListener() {  
  5.                   
  6.                 @Override  
  7.                 public void onClick(DialogInterface dialog, int which) {  
  8.                     // TODO Auto-generated method stub  
  9.                       
  10.                 }  
  11.             });  
  12.             b.setNegativeButton("否"new DialogInterface.OnClickListener() {  
  13.                   
  14.                 @Override  
  15.                 public void onClick(DialogInterface dialog, int which) {  
  16.                     // TODO Auto-generated method stub  
  17.                       
  18.                 }  
  19.             });  
  20.             return b.create();  
AlertDialog.Builder b=new  AlertDialog.Builder(this);
b.setTitle("简单的");
			b.setMessage("this is a simple dialog");
			b.setPositiveButton("是", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					
				}
			});
			b.setNegativeButton("否", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					
				}
			});
			return b.create();


效果如下

2.列表对话框

  1. b.setTitle("列表");  
  2.             //b.setMessage("message");这行代码不要有  
  3.             b.setItems(items, new DialogInterface.OnClickListener() {  
  4.                   
  5.                 @Override  
  6.                 public void onClick(DialogInterface dialog, int which) {  
  7.                     // TODO Auto-generated method stub  
  8.                     Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();  
  9.                       
  10.                 }  
  11.             });  
  12.             return b.create();  
b.setTitle("列表");
			//b.setMessage("message");这行代码不要有
			b.setItems(items, new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();
					
				}
			});
			return b.create();

items是一个String数组
效果图

3.单选对话框

  1. b.setTitle("请选择颜色");  
  2.             b.setSingleChoiceItems(items, -1,  new DialogInterface.OnClickListener() {  
  3.                   
  4.                 @Override  
  5.                 public void onClick(DialogInterface dialog, int which) {  
  6.                     // TODO Auto-generated method stub  
  7.                     Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();  
  8.                       
  9.                 }  
  10.             });  
  11.             b.setPositiveButton("是"new DialogInterface.OnClickListener() {  
  12.                   
  13.                 @Override  
  14.                 public void onClick(DialogInterface dialog, int which) {  
  15.                     // TODO Auto-generated method stub  
  16.                       
  17.                 }  
  18.             });  
  19.             b.setNegativeButton("否"new DialogInterface.OnClickListener() {  
  20.                   
  21.                 @Override  
  22.                 public void onClick(DialogInterface dialog, int which) {  
  23.                     // TODO Auto-generated method stub  
  24.                       
  25.                 }  
  26.             });  
  27.             return b.create();  
  28.           
b.setTitle("请选择颜色");
			b.setSingleChoiceItems(items, -1,  new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					Toast.makeText(AndroidDialogActivity.this, items[which], Toast.LENGTH_SHORT).show();
					
				}
			});
			b.setPositiveButton("是", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					
				}
			});
			b.setNegativeButton("否", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					
				}
			});
			return b.create();
		

效果图

4.多选对话框

 

  1. boolean []ddd=new boolean[3];  
  2.             b.setTitle("请选择颜色");  
  3.             b.setMultiChoiceItems(items, ddd, new DialogInterface.OnMultiChoiceClickListener(){  
  4.   
  5.                 @Override  
  6.                 public void onClick(DialogInterface dialog, int which,  
  7.                         boolean isChecked) {  
  8.                     // TODO Auto-generated method stub  
  9.                       
  10.                 }  
  11.                   
  12.             });  
  13.               
  14.             return b.create();  
boolean []ddd=new boolean[3];
			b.setTitle("请选择颜色");
			b.setMultiChoiceItems(items, ddd, new DialogInterface.OnMultiChoiceClickListener(){

				@Override
				public void onClick(DialogInterface dialog, int which,
						boolean isChecked) {
					// TODO Auto-generated method stub
					
				}
				
			});
			
			return b.create();


效果图


5.进度条对话框

  1. Handler hand=new Handler(){  
  2.   
  3.         @Override  
  4.         public void handleMessage(Message msg) {  
  5.             // TODO Auto-generated method stub  
  6.             super.handleMessage(msg);  
  7.             if(progressint>=100)  
  8.             {  
  9.                 pd.dismiss();  
  10.             }  
  11.             else  
  12.             {  
  13.                 progressint++;  
  14.                 pd.setProgress(progressint);  
  15.                 hand.sendEmptyMessageDelayed(0100);  
  16.             }  
  17.               
  18.         }  
  19.           
  20.     };  
  21. pd=new ProgressDialog(this);  
  22.             pd.setTitle("进度对话框");  
  23.             pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);  
  24.             pd.setMax(100);  
  25.             AndroidDialogActivity.this.hand.sendEmptyMessage(0);  
  26.             pd.setButton(DialogInterface.BUTTON_POSITIVE, "确定"new DialogInterface.OnClickListener(){  
  27.   
  28.                 @Override  
  29.                 public void onClick(DialogInterface dialog, int which) {  
  30.                     // TODO Auto-generated method stub  
  31.                       
  32.                       
  33.                 }});  
  34.             return pd;  
Handler hand=new Handler(){

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			if(progressint>=100)
			{
				pd.dismiss();
			}
			else
			{
				progressint++;
				pd.setProgress(progressint);
				hand.sendEmptyMessageDelayed(0, 100);
			}
			
		}
		
	};
pd=new ProgressDialog(this);
			pd.setTitle("进度对话框");
			pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
			pd.setMax(100);
			AndroidDialogActivity.this.hand.sendEmptyMessage(0);
			pd.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener(){

				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					
					
				}});
			return pd;


效果图

6.代码自定义对话框

  1. EditText et=new EditText(this);  
  2.             et.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD|InputType.TYPE_CLASS_TEXT);  
  3.             b.setTitle("请输入密码");  
  4.             b.setView(et);  
  5.             return b.create();  
EditText et=new EditText(this);
			et.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD|InputType.TYPE_CLASS_TEXT);
			b.setTitle("请输入密码");
			b.setView(et);
			return b.create();


效果图

7.XML文件自定义对话框

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.   
  7.     <TextView  
  8.         android:id="@+id/textView1"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="用户名" />  
  12.     <EditText  
  13.        android:id="@+id/EditText1"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:text="TextView"  
  17.           
  18.         />  
  19.   
  20.     <TextView  
  21.         android:id="@+id/textView2"  
  22.          android:layout_width="fill_parent"  
  23.         android:layout_height="wrap_content"  
  24.         android:text="密码" />  
  25.   
  26.     <EditText  
  27.        android:id="@+id/EdiText2"  
  28.         android:layout_width="fill_parent"  
  29.         android:layout_height="wrap_content"  
  30.         android:text="TextView"  
  31.         android:inputType="textPassword"  
  32.           
  33.         />  
  34.     <Button  
  35.         android:id="@+id/buttonyes"  
  36.          android:layout_width="fill_parent"  
  37.         android:layout_height="wrap_content"  
  38.         android:text="确定" />  
  39.   
  40. </LinearLayout>  
<?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="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="用户名" />
    <EditText
       android:id="@+id/EditText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        
        />

    <TextView
        android:id="@+id/textView2"
         android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="密码" />

    <EditText
       android:id="@+id/EdiText2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:inputType="textPassword"
        
        />
    <Button
        android:id="@+id/buttonyes"
         android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="确定" />

</LinearLayout>


Java代码

  1. b.setIcon(R.drawable.ic_launcher);  
  2.             b.setTitle("自定义对话框");  
  3.             LayoutInflater li=LayoutInflater.from(this);  
  4.             View v=li.inflate(R.layout.info, null);  
  5.             Button yes=(Button) v.findViewById(R.id.buttonyes);  
  6.             yes.setOnClickListener(new OnClickListener(){  
  7.   
  8.                 @Override  
  9.                 public void onClick(View v) {  
  10.                     // TODO Auto-generated method stub  
  11.                     Toast.makeText(AndroidDialogActivity.this"Hello World", Toast.LENGTH_SHORT).show();  
  12.                 }});  
  13.             b.setView(v);  
  14.             return b.create();  
b.setIcon(R.drawable.ic_launcher);
			b.setTitle("自定义对话框");
			LayoutInflater li=LayoutInflater.from(this);
			View v=li.inflate(R.layout.info, null);
			Button yes=(Button) v.findViewById(R.id.buttonyes);
			yes.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast.makeText(AndroidDialogActivity.this, "Hello World", Toast.LENGTH_SHORT).show();
				}});
			b.setView(v);
			return b.create();


效果图

 下载工程:下载

转自:http://blog.csdn.net/zhy_cheng/article/details/8003467

转自:http://www.cnblogs.com/Gaojiecai/archive/2011/12/10/2283156.html

数据治理是确保数据准确性、可靠性、安全性、可用性和完整性的体系和框架。它定义了组织内部如何使用、存储、保护和共享数据的规则和流程。数据治理的重要性随着数字化转型的加速而日益凸显,它能够提高决策效率、增强业务竞争力、降低风险,并促进业务创新。有效的数据治理体系可以确保数据在采集、存储、处理、共享和保护等环节的合规性和有效性。 数据质量管理是数据治理中的关键环节,它涉及数据质量评估、数据清洗、标准化和监控。高质量的数据能够提升业务决策的准确性,优化业务流程,并挖掘潜在的商业价值。随着大数据和人工智能技术的发展,数据质量管理在确保数据准确性和可靠性方面的作用愈发重要。企业需要建立完善的数据质量管理和校验机制,并通过数据清洗和标准化提高数据质量。 数据安全与隐私保护是数据治理中的另一个重要领域。随着数据量的快速增长和互联网技术的迅速发展,数据安全与隐私保护面临前所未有的挑战。企业需要加强数据安全与隐私保护的法律法规和技术手段,采用数据加密、脱敏和备份恢复等技术手段,以及加强培训和教育,提高安全意识和技能水平。 数据流程管理与监控是确保数据质量、提高数据利用率、保护数据安全的重要环节。有效的数据流程管理可以确保数据流程的合规性和高效性,而实时监控则有助于及时发现并解决潜在问题。企业需要设计合理的数据流程架构,制定详细的数据管理流程规范,并运用数据审计和可视化技术手段进行监控。 数据资产管理是将数据视为组织的重要资产,通过有效的管理和利用,为组织带来经济价值。数据资产管理涵盖数据的整个生命周期,包括数据的创建、存储、处理、共享、使用和保护。它面临的挑战包括数据量的快速增长、数据类型的多样化和数据更新的迅速性。组织需要建立完善的数据管理体系,提高数据处理和分析能力,以应对这些挑战。同时,数据资产的分类与评估、共享与使用规范也是数据资产管理的重要组成部分,需要制定合理的标准和规范,确保数据共享的安全性和隐私保护,以及建立合理的利益分配和权益保障机制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值