当前位置: 首页 > news >正文

有的网站网速慢网站推广优化招聘

有的网站网速慢,网站推广优化招聘,比较有名的公司网站,电子商务网站建设期末试题对话框对于应用是必不可少的一个组件,在Android中也不例外。对话框对于一些提示重要信息,或者询问用户采取决定是否采取的特殊动作等额外交互的内容很有帮助。本篇博客将讲解一下Android下对话框的使用。 一、Dialog的分类 Dialog对话框即一个小窗口&am…

       对话框对于应用是必不可少的一个组件,在Android中也不例外。对话框对于一些提示重要信息,或者询问用户采取决定是否采取的特殊动作等额外交互的内容很有帮助。本篇博客将讲解一下Android下对话框的使用。

一、Dialog的分类

  Dialog对话框即一个小窗口,并不会填满整个屏幕,通常是以模态显示,要求用户必须采取行动才能继续进行剩下的操作。  

      Android提供了丰富的对话框支持,它提供了如下4中常用的对话框:

     1)AlertDialog:警告对话框,使用最广泛功能最丰富的一个对话框。

     2)ProgressDialog:进度条对话框,只是对进度条进行了简单的封装。

     3)DatePickerDialog:日期对话框。

     4)TimePickerDialog:时间对话框。

  所有的对话框,都是直接或间接继承自Dialog类,而AlterDialog直接继承自Dialog,其他的几个类均继承自AlterDialog。


二、AlertDialog

       AlertDialog的构造方法全部是Protected的,所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法。以下为基本方法及说明。


2.1 确定取消对话框

      对话框中有2个按钮,通过调用 setPositiveButton 方法和 setNegativeButton 方法 可以设置按钮的显示内容以及按钮的监听事件


AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);   //创建AlertDialogbuilder.setIcon(R.drawable.icon);  builder.setTitle("你确定要离开吗?");  builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  //这里添加点击确定后的逻辑  showDialog("你选择了确定");  }  });  builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  //这里添加点击确定后的逻辑  showDialog("你选择了取消");  }  });  builder.create().show();
<span style="font-size:14px;">private void showDialog(String str) {  
//用于onClick操作后监听内容信息,下同AlertDialog.Builder(MainDialog.this)  .setMessage(str)  .show();  
}  </span>


2.2 多个按钮信息框


AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);           
builder.setIcon(R.drawable.icon);  
builder.setTitle("投票");  
builder.setMessage("您认为什么样的内容能吸引您?");  
builder.setPositiveButton("有趣味的", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  showDialog("你选择了有趣味的");  }  
});  
builder.setNeutralButton("有思想的", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  showDialog("你选择了有思想的");                      }  
});  
builder.setNegativeButton("主题强的", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  showDialog("你选择了主题强的");    }  
});  
builder.create().show();  


2.3 列表框

final String[] mItems = {"item0","item1","itme2","item3","itme4","item5","item6"};  //创建数组用于列表选择
AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);   builder.setTitle("列表选择框");  builder.setItems(mItems, new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int which) {  //点击后弹出窗口选择了第几项  showDialog("你选择的id为" + which + " , " + mItems[which]);  }  });  builder.create().show();  


2.4 单项选择列表


int mSingleChoiceID = -1;  //用于记录单选中的IdAlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);   mSingleChoiceID = -1;  
builder.setIcon(R.drawable.icon);  builder.setTitle("单项选择");  builder.setSingleChoiceItems(mItems, 0, new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  mSingleChoiceID = whichButton;  showDialog("你选择的id为" + whichButton + " , " + mItems[whichButton]);  }  });  builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  if(mSingleChoiceID > 0) {  showDialog("你选择的是" + mSingleChoiceID);  }  }  });  builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  }  });  builder.create().show();  


2.5 多项选择列表框


       MultiChoiceID 用于记录多选选中的id号 存在ArrayList中,选中后 add 进ArrayList,取消选中后 remove 出ArrayList
ArrayList <Integer>MultiChoiceID = new ArrayList <Integer>();  AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);   MultiChoiceID.clear();  
builder.setIcon(R.drawable.icon);  builder.setTitle("多项选择");  builder.setMultiChoiceItems(mItems,  new boolean[]{false, false, false, false, false, false, false},  new DialogInterface.OnMultiChoiceClickListener() {  public void onClick(DialogInterface dialog, int whichButton,  boolean isChecked) {  if(isChecked) {  MultiChoiceID.add(whichButton);  showDialog("你选择的id为" + whichButton + " , " + mItems[whichButton]);  }else {  MultiChoiceID.remove(whichButton);  }  }  });  builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  String str = "";  int size = MultiChoiceID.size();  for (int i = 0 ;i < size; i++) {  str+= mItems[MultiChoiceID.get(i)] + ", ";  }  showDialog("你选择的是" + str);  }  });  builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  }  });  builder.create().show();  


2.6 进度条框


      点击进度条框按钮后,开启一个线程计算读取的进度。假设读取结束为 100,Progress在小于100的时候一直在线程中做循环++ 直到读取结束后,停止线程。
     mProgressDialog = new ProgressDialog(MainDialog.this);  mProgressDialog.setIcon(R.drawable.icon);  mProgressDialog.setTitle("进度条窗口");  mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);  mProgressDialog.setMax(MAX_PROGRESS);  mProgressDialog.setButton("确定", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  //这里添加点击后的逻辑  }  });  mProgressDialog.setButton2("取消", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  //这里添加点击后的逻辑  }  });  mProgressDialog.show();  new Thread(this).start();  ic void run() {  
int Progress = 0;  
while(Progress < MAX_PROGRESS) {  
try {  Thread.sleep(100);  Progress++;    mProgressDialog.incrementProgressBy(1);  
} catch (InterruptedException e) {  // TODO Auto-generated catch block  e.printStackTrace();  
}  }  


2.7 自定义布局

      自定义布局在Android的开发中非常重要,因为它能让开发者做出自己五彩缤纷的Activity,而不用去使用系统枯燥的界面。比如我们在开发过程当中,要通过介绍系统发送的一个广播弹出一个dialog,但是dialog必需是基于activity才能呈现出来,如果没有activity 的话,程序就会崩溃。所以我们可以写一个自定义的 dialog 把它定义成一个activity,这样我们收到一条打开dialog的广播后,直接启动这个 activity  程序正常运行~~ 
     注明:下面这个例子只是写了自定义dialog 没有把它单独的写在一个activity中 如果需要的话 可以自己改一下。
 AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this);   LayoutInflater factory = LayoutInflater.from(this);  final View textEntryView = factory.inflate(R.layout.test, null);  builder.setIcon(R.drawable.icon);  builder.setTitle("自定义输入框");  builder.setView(textEntryView);  builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  EditText userName = (EditText) textEntryView.findViewById(R.id.etUserName);  EditText password = (EditText) textEntryView.findViewById(R.id.etPassWord);  showDialog("姓名 :"  + userName.getText().toString()  + "密码:" + password.getText().toString() );  }  });  builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {  public void onClick(DialogInterface dialog, int whichButton) {  }  });  builder.create().show();  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_height="wrap_content"   android:layout_width="wrap_content"  android:orientation="horizontal"  android:id="@+id/test">  
<LinearLayout  android:layout_height="wrap_content"   android:layout_width="wrap_content"  android:orientation="horizontal"  android:id="@+id/dialogname">  <TextView android:layout_height="wrap_content"  android:layout_width="wrap_content"  android:id="@+id/tvUserName"   android:text="姓名:" />  <EditText android:layout_height="wrap_content"  android:layout_width="wrap_content"   android:id="@+id/etUserName"   android:minWidth="200dip"/>  
</LinearLayout>    
<LinearLayout  android:layout_height="wrap_content"   android:layout_width="wrap_content"  android:orientation="horizontal"  android:id="@+id/dialognum"  android:layout_below="@+id/dialogname"  
>  <TextView android:layout_height="wrap_content"  android:layout_width="wrap_content"  android:id="@+id/tvPassWord"   android:text="密码:" />  <EditText android:layout_height="wrap_content"  android:layout_width="wrap_content"   android:id="@+id/etPassWord"   android:minWidth="200dip"/>  
</LinearLayout>    
</RelativeLayout>


三、ProgressDialog

       有些时候,只是需要提示用户等待,比如在执行耗时操作等的时候,可以使用进度对话框来显示一个进度信息,提示用户等待,这个时候可以使用ProgressDialog。ProgressDialog的使用方式大部分可以参见ProgressBar,其实就是一个封装了ProgressBar的对话框。
  ProgressDialog有两种显示方式,一种是以一个滚动的环状图标,可以显示一个标题和一段文本内容的等待对话框;另外一种是带刻度的进度条,和常规的进度条用法一致。两种样式通过ProgressDialog.setProgressStyle(int style)设置,可以通过ProgressDialog的两个常量进行设置:STYLE_HORIZONTAL:刻度滚动;STYLE_SPINNER:图标滚动,默认选项。
  对于图标滚动,可以使用两种方式实现,一种是常规的调用构造函数,再设置对应的属性;另外一种是直接使用ProgressDialog的静态方法show(),直接返回一个ProgressDialog对象,并且调用show()方法。
 // 第一种方法,使用ProgressDialog构造函数progressDialog = new ProgressDialog(MainActivity.this);progressDialog.setIcon(R.drawable.ic_launcher);progressDialog.setTitle("等待");progressDialog.setMessage("正在加载....");progressDialog.show();// 第二种方法,使用静态的show方法progressDialog=ProgressDialog.show(MainActivity.this, "等待", "正在加载....", false, false);new Thread(new Runnable() {@Overridepublic void run() {try {Thread.sleep(5000);            } catch (Exception e) {e.printStackTrace();}finally{progressDialog.dismiss();}                        }}).start();


转自http://www.cnblogs.com/afirefly/archive/2011/09/22/2185645.html

       http://www.apkbus.com/android-138036-1-1.html?_dsign=a2282f7e

http://www.dt0577.cn/news/44427.html

相关文章:

  • 1000平方办公室装修多少钱seo顾问服务
  • dede 网站打开慢网站推广费用
  • 小说网站建设多少钱营销手机系统安装
  • 常州网站专业制作提升seo搜索排名
  • 北京网站建设服务制作app平台需要多少钱
  • 用什么软件做购物网站海南网站制作
  • 点网站出图片怎么做百度站长平台app
  • 阿里云怎样做公司网站江苏网站seo营销模板
  • 原阳网站建设哪家好怎样申请网站注册
  • 顶级域名备案 二级域名 医疗网站东莞网站seo技术
  • 淘宝联盟+做网站网站快速刷排名工具
  • 泰安网站建设电话除了百度指数还有哪些指数
  • 广州网站建设哪家专业简短的营销软文范文
  • 做网站业务员如何跟客户沟通seo排名工具
  • 广西城乡建设厅网站首域名注册新网
  • 可在哪些网站做链接seo 推广服务
  • 本机运行wordpress免费下载优化大师
  • 北京网站建设外包公司排名app运营方案
  • 加强政协网站建设2022年适合小学生的新闻
  • 政府网站改版方案seo管理与优化期末试题
  • 自己做的网站怎么挣钱seo综合查询是什么
  • 公众号开发是不是网站开发地推接单正规平台
  • 做地方网站收益怎么样品牌营销策划书
  • 买的网站模板怎么做好用的搜索引擎
  • 网页版梦幻西游科举答案长春百度快速优化
  • 简约好看的网站模板做网络推广需要多少钱
  • 建设企业网站的需求分析网络营销外包公司
  • 免费做网站手机软件网站收录排名
  • 做网站1008做网站 - 百度生哥seo博客
  • 全国装修公司排名前十强优化大师专业版