I am creating a Custom dialog where I want to use both DatePicker and TimePicker .Although I am able to use TimePicker as I want but for DatePicker I am short of ideas. Please Help Me. My Code is as follows
My XML Layout file is...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TimePicker android:id="@+id/timePicker1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TimePicker>
<DatePicker android:id="@+id/datePicker1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></DatePicker>
<Button android:id="@+id/buttondatetime" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="OK" />
And My Java Code for Creating Custom Dialog is
void dialogDateTime()
{
dialog = new Dialog(this);
dialog.setContentView(R.layout.datetime);
dialog.setCancelable(true);
dialog.setTitle("This is Dialog 1");
dialog.show();
TimePicker time_picker = (TimePicker) dialog.findViewById(R.id.timePicker1);
time_picker.setOnTimeChangedListener(new OnTimeChangedListener()
{
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minutes)
{
// TODO Auto-generated method stub
}
});
DatePicker date_picker = (DatePicker) dialog.findViewById(R.id.datePicker1);
Button btn_ok = (Button) dialog.findViewById(R.id.buttondatetime);
btn_ok.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
String text = "Time "+hours+":"+minute;
tv_date_time.setText(text);
dialog.cancel();
}
});
}
@Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub
switch (id)
{
case DIALOG_1:
dialogDateTime();
break;
case DIALOG_2:
dialogTwo();
break;
default:
break;
}
return super.onCreateDialog(id);
}
I am not getting any method for DatePicker as in TimePicker So I am not able to use DatePicker Please Help