Puede muy fácilmente tener acceso a la DatePicker
objeto encapsulado por el DatePickerDialog
mediante la reflexión
DatePickerDialog dialog = ... // create dialog
Field mDatePickerField = dialog.getClass().getDeclaredField("mDatePicker");
mDatePickerField.setAccessible(true);
DatePicker mDatePickerInstance = (DatePicker) mDatePickerField.get(dialog);
Ejemplos para ser aplicados:
android.app.DatePickerDialog
final
Calendar cal = Calendar.getInstance();
final
Long time = getValue();
if
(time !=
null
) {
cal.setTimeInMillis(time.longValue());
}
return
new
DatePickerDialog(
getContext(),
this
,
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH));
switch
(id) {
case
TIME_DIALOG_ID:
return
new
TimePickerDialog(
this
,
mTimeSetListener, mHour, mMinute,
false
);
case
DATE_DIALOG_ID:
return
new
DatePickerDialog(
this
,
mDateSetListener,
mYear, mMonth, mDay);
}
return
null
;
}
@Override
protected
Dialog onCreateDialog(
int
id) {
switch
(id) {
case
DATE_DIALOG_ID:
return
new
DatePickerDialog(
this
,
this
, mYear, mMonth, mDay);
default
:
break
;
}
return
null
;
}
} }); mMonthButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { new DatePickerDialog(BudgetList. this , mDateSetListener, Buxoid.mYear, Buxoid.mMonth, 1 ).show(); } }); registerForContextMenu(getListView()); } |
}
});
mMonthButton.setOnClickListener(
new
View.OnClickListener() {
public
void
onClick(View view) {
new
DatePickerDialog(Analysis.
this
, mDateSetListener, Buxoid.mYear, Buxoid.mMonth,
1
).show();
}
});
}
}); // set the onclick listener for the change date button mDate.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { new DatePickerDialog(EditTransaction. this , mDateSetListener, mYear, mMonth- 1 , mDay).show(); } }); mTransId = icicle != null ? icicle.getLong(BuxoidDb.TRANS_ROWID) : null ; mAccountId = icicle != null ? icicle.getString(BuxoidDb.TRANS_ACCOUNTID) : null ; |
No hay comentarios:
Publicar un comentario