What I need in my project is a DatePickerFragment with year and month selection. I have implemented but It is not working in "Lollipop" Version. What i got there is full calendar, which I don't need.
I have found that by adding datepicker tag with android:calendarViewShown="false" android:datePickerMode="spinner" to show date picker without calendar in all versions. But what I need is is the same in the datepicker fragment.
The code which I have implemented is given below
Main Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//showDatePicker();
DatePickerFragment date = new DatePickerFragment();
date.show(getSupportFragmentManager(), "Date Picker");
}
});
}
Fragment code is as follows
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
What I need for all the versions is given in screenshot below
[![Requirement][2]][2]