免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1499 | 回复: 0
打印 上一主题 下一主题

Android学习笔记(6)—关于Dialog的简单体验 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-30 11:22 |只看该作者 |倒序浏览
继续android.app中的几个类的学习,今天的内容是那几个Dialog的体验。
注意到android.app包下除了Dialog(可用于制作复杂的对话框)以外,还包括了几个系统定义好的对话框类,如DatePickerDialog、TimePickerDialog及AlertDialog。
其中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方法中就可以得到选择的日期了。而TimePickerDialog与DatePickerDialog使用如出一辙,就不多说了。
看看另一个ProgressDialog的用法吧,这个类与AlertDialog一样包含了多个static的方法,所以使用起来是非常方便的。比如说,如果我们需要用它来表示一个长时间的操作,很简单的用一句话就可以了:
ProgressDialog.show(this,null, "operation running...",true,true);
URL:http://www.sf.org.cn/Android/lumen/20981.html
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/90973/showart_1914960.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP