Reputation: 69
How can I create a Date time picker that is not on a dialog. Do you guys have an idea? Like this
Any suggestions could help alot. Thanks!
Upvotes: 1
Views: 1933
Reputation: 159
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:spinnersShown="true" />
Upvotes: 4
Reputation: 3841
try this
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/date_picker"
android:layout_width="fill_parent"
android:spinnersShown="true"
android:calendarViewShown="false"
android:layout_height="fill_parent"/>
public class DatePickerFragment extends DialogFragment {
private OnDateChosenListener mListener;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final DatePicker datePicker = (DatePicker) getActivity().getLayoutInflater().
inflate(R.layout.dialog_date_picker, null);
//Set an initial date for the picker
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
//Set the date now
datePicker.updateDate(year, month, day);
//create the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//set the title
builder.setTitle(getString(R.string.date_picker_title))
.setView(datePicker)
.setPositiveButton(R.string.picker_confirmation, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do some stuff with the date
}
});
return builder.create();
}
// from an Activity...
DatePickerFragment dialog = new DatePickerFragment();
dialog.show(getFragmentManager(), "datePicker");
for more information follow this link Datepicker Android
Upvotes: 0
Reputation: 371
You can add below line in your xml file.
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"/>
Upvotes: 0