7
votes

I want create a DatePicker like this:

http://3.bp.blogspot.com/-SK2ljlhHiCU/UaiEjF1lhGI/AAAAAAABJqs/0uWv7oMxdG4/s640/android-calendar-time-control-1.png

possibily without using external libraries. For first, is it possible? Now i can create a simple DatePickerDialog in this way:

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

public EditText activity_edittext;

public DatePickerFragment(EditText edit_text) {
    activity_edittext = edit_text;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    // Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), this, year, month, day);
}

    @Override
    public void onDateSet(DatePicker view, int year, int month, int day) {
        activity_edittext.setText(String.valueOf(month + 1 ) + "/" + String.valueOf(day) + "/" + String.valueOf(year));
    }
}

but it appears as normal Dialog and not as a "clock". Any idea?

1
It seems to me being more of a TimePicker rather than a DatePicker. Anyway, it's possible to do something similar, but you have to build a custom control - Phantômaxx
I think it's the same.. There is the TimePicker and the DatePicker too building in this way. But i can't find any guide/tutorial about how do it. IT's the same google use for its calendar/agenda when you set an event. - Atlas91

1 Answers

6
votes

You should look into the android-betterpickers library: https://github.com/derekbrameyer/android-betterpickers/

Another library that provides a port of this date and time picker dialogs: https://github.com/flavienlaurent/datetimepicker