日期与时间的对话框
来源:互联网 发布:淘宝退款假冒品牌 编辑:程序博客网 时间:2024/05/30 07:12
public class MainActivity extends Activity {
private Button dateBtn = null;
private Button timeBtn = null;
private EditText et=null;
private final static int DATE_DIALOG = 0;
private final static int TIME_DIALOG = 1;
private Calendar c = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=(EditText)findViewById(R.id.et);
dateBtn = (Button) findViewById(R.id.dateBtn);
timeBtn = (Button) findViewById(R.id.timeBtn);
dateBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
showDialog(DATE_DIALOG);
}
});
timeBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
showDialog(TIME_DIALOG);
}
});
}
/**
* 创建日期及时间选择对话框
*/
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DATE_DIALOG:
c = Calendar.getInstance();
dialog = new DatePickerDialog(
this,
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker dp, int year,int month, int dayOfMonth) {
et.setText("您选择了:" + year + "年" + (month+1) + "月" + dayOfMonth + "日");
}
},
c.get(Calendar.YEAR), // 传入年份
c.get(Calendar.MONTH), // 传入月份
c.get(Calendar.DAY_OF_MONTH) // 传入天数
);
break;
case TIME_DIALOG:
c=Calendar.getInstance();
dialog=new TimePickerDialog(
this,
new TimePickerDialog.OnTimeSetListener(){
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
et.setText("您选择了:"+hourOfDay+"时"+minute+"分");
}
},
c.get(Calendar.HOUR_OF_DAY),
c.get(Calendar.MINUTE),
false
);
break;
}
return dialog;
}
}
//布局layout代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText android:id="@+id/et"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorVisible="false" />
<Button android:text="日期对话框"
android:id="@+id/dateBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:text="时间对话框"
android:id="@+id/timeBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<DigitalClock
android:text="@+id/digitalClock"
android:textSize="20dip"
android:gravity="center"
android:id="@+id/DigitalClock01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<AnalogClock
android:id="@+id/analogClock"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
- 日期与时间的对话框
- 日期与时间选择对话框的实现
- 时间对话框的使用和日期对话框的使用
- android 日期 时间对话框
- 日期时间对话框
- Day21-日期时间对话框
- 日期时间对话框
- 时间日期选择器、对话框
- 日期、时间选择对话框
- 日期、时间选择对话框
- Android时间、日期对话框
- 日期时间对话框
- 日语的时间与日期
- 时间与日期的转换
- 时间与日期的转换
- 下一秒的日期与时间
- 安卓通知的使用系列7:对话框通知的使用之日期对话框、时间对话框
- Android 时间和日期对话框
- 一套通过c# sap-rfc 完整处理一个bdc凭证的程序代码
- JavaScript的实现
- ListView中添加Button后,Button的点击事件和ListView的点击事件冲突
- 转]在C++编译器下dlsym()引发的思考
- NSDictionary&& NSMutableDictionary使用
- 日期与时间的对话框
- java.util.Collection体系源码解读<一>Collection简介
- Web项目的前台兼容性问题--宏观篇
- 聚合函数与分组
- python求最优解的集中算法
- sql面试
- Android中Service的使用详解和注意点(LocalService)
- Ubuntu下迁移MySQL数据库文件目录
- treemap