关于Dialog的简单体验
生活随笔
收集整理的這篇文章主要介紹了
关于Dialog的简单体验
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注意到android.app包下除了Dialog(可用于制作復雜的對話框)以外,還包括了幾個系統定義好的對話框類,如 DatePickerDialog、TimePickerDialog及AlertDialog。 其中AlertDialog我上回用過一次,基本上就那樣子了,今天看看另外兩個對話框的使用吧。 首先是DatePickerDialog類,修改代碼如下:
很 簡單的,無非是需要一個OnDateSetListener接口的實現而已,在它里面的dateSet方法中就可以得到選擇的日期了。而 TimePickerDialog與DatePickerDialog使用如出一轍,就不多說了。 看看另一個ProgressDialog的用法吧,這個類與AlertDialog一樣包含了多個static的方法,所以使用起來是非常方便的。 比如說,如果我們需要用它來表示一個長時間的操作,很簡單的用一句話就可以了:
今天先到這里,下回再看看Service和Notification的使用。
| 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); |
轉載于:https://blog.51cto.com/dadou/367690
總結
以上是生活随笔為你收集整理的关于Dialog的简单体验的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 传统企业建模原理及建模体系介绍
- 下一篇: 浅谈腾讯微博与新浪微博的优劣