- 论坛徽章:
- 0
|
继续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);
今天先到这里,下回再看看Service和Notification的使用。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/85805/showart_1421764.html |
|