Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9087480
  • 博文数量: 1732
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19830
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1732)

文章存档

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: LINUX

2009-04-30 11:22:39

继续android.app中的几个类的学习,今天的内容是那几个Dialog的体验。

注意到android.app包下除了Dialog(可用于制作复杂的对话框)以外,还包括了几个系统定义好的对话框类,如DatePickerDialogTimePickerDialogAlertDialog

其中AlertDialog我上回用过一次,基本上就那样子了,今天看看另外两个对话框的使用吧。

首先是DatePickerDialog类,修改代码如下:

public class HelloTwoC extends Activity implements OnClickListener, OnDateSetListener ...{
 
public HelloTwoC() ...{
   
super();
 }
 
public void onCreate(Bundle icicle) ...{
     
super.onCreate(icicle);
     setTheme(android.R.style.Theme_Dark);
     setContentView(R.layout.mainc);
        
     Button btn = (Button)findViewById(R.id.date);
     btn.setOnClickListener(
this);        
 }
 @Override
 
public void onClick(View v) ...{
   Calendar d = Calendar.getInstance(Locale.CHINA);
   d.setTime(
new Date());
   DatePickerDialog dlg=
new DatePickerDialog(this,this,d.get(Calendar.YEAR),d.get(Calendar.MONTH),d.get(Calendar.DAY_OF_MONTH),d.get(Calendar.DAY_OF_WEEK));
   dlg.show(
); 
 }
 @Override
 public void dateSet(DatePicker dp, int y, int m, int d) ...{
  TextView txt = (TextView)findViewById(R.id.text);
  txt.setText(Integer.toString(y)+"-"+Integer.toString(m)+"-"+Integer.toString(d));
 }
}

很简单的,无非是需要一个OnDateSetListener接口的实现而已,在它里面的dateSet方法中就可以得到选择的日期了。而TimePickerDialogDatePickerDialog使用如出一辙,就不多说了。

看看另一个ProgressDialog的用法吧,这个类与AlertDialog一样包含了多个static的方法,所以使用起来是非常方便的。比如说,如果我们需要用它来表示一个长时间的操作,很简单的用一句话就可以了:

ProgressDialog.show(this,null, "operation running...",true,true);

URL
阅读(1579) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~