目前我正在使用带有修改的本机对话框来隐藏日期微调器,并且工作正常。
但是现在我想以这样的格式设置日期,当我旋转月份微调器或年份微调器时,对话框只显示月份和年份而不是完整的日历日期,我的日期选择器对话框的自定义代码如下:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
// set date picker as current date
DatePickerDialog datePickerDialog = this.customDatePicker();
return datePickerDialog;
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener
= new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
@Override
public void onDateSet(DatePicker datepickerView, int selectedYear,
int selectedMonth, int selectedDay) {
/* year = selectedYear;
month = selectedMonth;
day = selectedDay;*/
mynewYear=selectedYear;
myNewMonth=selectedMonth;
myNewDay=selectedDay;
try {
checkDate();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*time_date_TV.setText(new StringBuilder()
.append(myNewMonth + 1).append("/")
.append(myNewDay ).append("/").append(mynewYear));
*/
}
};
private DatePickerDialog customDatePicker() {
DatePickerDialog dpd = new DatePickerDialog(context, android.R.style.Theme_Holo_Light_Dialog,datePickerListener,
year, month,day );
if(month==0)
{
mmonth="January";
}
if(month==1)
{
mmonth="Faburary";
}
if(month==2)
{
mmonth="March";
}
if(month==3)
{
mmonth="April";
}
if(month==4)
{
mmonth="May";
}
if(month==5)
{
mmonth="June";
}
if(month==6)
{
mmonth="July";
}
if(month==7)
{
mmonth="August";
}
if(month==8)
{
mmonth="September";
}if(month==9)
{
mmonth="October";
}
if(month==10)
{
mmonth="November";
}
if(month==11)
{
mmonth="December";
}
dpd.setTitle(""+mmonth+", "+year);
try {
Field[] datePickerDialogFields = dpd.getClass().getDeclaredFields();
for (Field datePickerDialogField : datePickerDialogFields) {
if (datePickerDialogField.getName().equals("mDatePicker")) {
datePickerDialogField.setAccessible(true);
DatePicker datePicker = (DatePicker) datePickerDialogField
.get(dpd);
Field datePickerFields[] = datePickerDialogField.getType()
.getDeclaredFields();
for (Field datePickerField : datePickerFields) {
if ("mDayPicker".equals(datePickerField.getName())
|| "mDaySpinner".equals(datePickerField
.getName())) {
datePickerField.setAccessible(true);
Object dayPicker = new Object();
dayPicker = datePickerField.get(datePicker);
((View) dayPicker).setVisibility(View.GONE);
}
}
}
}
} catch (Exception ex) {
}
return dpd;
}
当对话框第一次弹出时它工作正常,因为我设置了标题
DatePickerDialog.setTitle("");
但是当对话框第一次弹出时效果很好但我想更新ondatechangelistner
所以我该怎么做