Reputation: 879
When I want to choose a day or a time in my Android Calendar App, a DatePicker opens. In this Datepicker, there are two buttons. The left one is labeled "Cancel", the right one is labeled "Set". In my Android application, I also have a DatePicker. In this DatePicker, the left Button is labeled "Set" and the right button is labeled "Cancel".
Why does these two Apps behave in a different way?
Does anyone knows, why the Buttons in these DatePickers are in a different order?
My Activity which calls the DatePickerFragment:
public void chooseDate(View v) {
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.setCalendar(termin);
newFragment.show(getFragmentManager(), "datePicker");
}
My DatePickerFragment class:
public class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
private Calendar calendar = Calendar.getInstance();
public Calendar getCalendar() {
return calendar;
}
public void setCalendar(Calendar calendar) {
this.calendar = calendar;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
((DatePickerMenu) getActivity()).setDate(year, month, day);
}
}
This is how it looks in the Calendar App:
This is how it looks in My App:
Upvotes: 1
Views: 1726
Reputation: 1
The Datepicker that appears in the application varies depending on the devices used. For the latest versions and advanced mobile phones the datepicker appearance varies compared to lower versions of android phones.
Upvotes: 0
Reputation: 14847
Maybe something like this?
Remember: You can set a title using builder.setTitle()
, in the screen i keep it empty because i don't know what you want to do with the title.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
DatePicker picker = new DatePicker(this);
picker.setCalendarViewShown(false);
builder.setView(picker);
builder.setNegativeButton("Cancel", null);
builder.setPositiveButton("Set", null);
builder.show();
If you want to extend DialogFragment
you can use the same code, and override onCreateDialog
.
I used an AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(new DatePicker(this));
builder.setNegativeButton("Cancel", null);
builder.setPositiveButton("Set", null);
builder.show();
Upvotes: 2