Hello developers,
I would like to create my own DateTimePicker Dialog. Therefor I build
a layout that I use in my Dialog. My Dialog starts when I click on a
Button. When the Dialog opens you can set date and time data. There is
still a Button to close the Dialog. This Button calls
Dialog.dismiss(). But it fails. Here is some code. Can someone tell
me, what I do wrong?
public class CreateActivity extends Activity{
private TextView mDateTimeDisplay;
private Dialog dateTimePicker;
private int mYear;
private int mMonth;
private int mDay;
private int mHour;
private int mMinute;
static final int DATE_DIALOG_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(de.android.todo.R.layout.create);
//http://babukuma.com/2010/01/android-custom-component-
datetimepicker_29.html
mDateTimeDisplay = (TextView)
findViewById(R.id.dateTimeDisplay);
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
dateTimePicker = new Dialog(this);
dateTimePicker.setContentView(R.layout.datetimepicker);
dateTimePicker.setTitle("DateTimePicker");
dateTimePicker.setCancelable(true);
DatePicker dp = (DatePicker)
dateTimePicker.findViewById(R.id.datePicker);
dp.init(mYear, mMonth, mMonth, onDateChangedListener);
TimePicker tp = (TimePicker)
dateTimePicker.findViewById(R.id.timePicker);
tp.setIs24HourView(true);
tp.setOnTimeChangedListener(onTimeChangedListener);
// display the current date
updateDisplay();
}
public void onClickShowMyDialog(final View v){
showDialog(DATE_DIALOG_ID);
}
public void onClickCloseDialog(final View v){
dateTimePicker.dismiss();
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID: return dateTimePicker;
}
return null;
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en