【www.gdgbn.com--.Net开发】

  清单文件

package="com.ljq.dialog"
android:versioncode="1"
android:versionname="1.0">

android:label="@string/app_name">









main.xml布局文件

android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorvisible="false" />
alertactivity类
package com.ljq.dialog;

import java.util.calendar;

import android.app.activity;
import android.app.datepickerdialog;
import android.app.dialog;
import android.app.timepickerdialog;
import android.os.bundle;
import android.view.view;
import android.widget.button;
import android.widget.datepicker;
import android.widget.edittext;
import android.widget.timepicker;

public class alertdialog 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
public void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.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;
}

}
运行结果 1、2、 <script type=text/网页特效> if ($ != jquery) { $ = jquery.noconflict(); } var islogined = false; var cb_blogid = 83240; var cb_entryid = 1980215; var cb_blogapp = "linjiqin"; var cb_bloguserguid = "a6448c44-d92c-e011-ac81-842b2b196315"; var cb_entrycreateddate = "2011/3/10 21:45:00"; </script>

本文来源:http://www.gdgbn.com/asp/29408/