文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Android学习笔记(6)—关于Dialog的简单体验

Android学习笔记(6)—关于Dialog的简单体验

时间:2009-04-30  来源:iibull

继续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
相关阅读 更多 +
排行榜 更多 +
摆个车游戏

摆个车游戏

休闲益智 下载
哈基跑酷最新版

哈基跑酷最新版

休闲益智 下载
冷血射手最新版

冷血射手最新版

休闲益智 下载