Android学习笔记(6)—关于Dialog的简单体验
2008-12-05 14:13
316 查看
继续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);
注意到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);
相关文章推荐
- Android学习笔记(6)-关于Dialog的简单体验
- Android学习笔记(5)-关于ListActivity的简单体验
- Android学习笔记(5)-关于ListActivity的简单体验
- Android学习笔记(5)-关于ListActivity的简单体验
- 关于Dialog的简单体验
- 关于Dialog的简单体验
- 体验C#——关于数组合并的简单算法的实现
- Android学习笔记(7)—关于Service和Notification的体验
- 简单的一个小体验关于div居中
- 【转】关于ListActivity的简单体验
- Android学习笔记----关于各种AlertDialog的总结
- Android中关于Dialog滑动弹出的简单动画的设置
- 关于最近流行的vuejs.angularjs,Reactjs等前端框架的简单对比及体验
- 关于仿ios底部向上弹出dialog的最简单方法
- [jQuery]关于jQueryUI的Dialog的简单封装
- 关于ListActivity的简单体验
- Android学习笔记(7)-关于Service和Notification的体验
- 关于java 8 9 10 新特性简单体验
- 关于一级指针和二级指针的简单见解
- 关于计算机同步概念的简单理解。