I am trying to use a DatePickerDialog in my application. it's working perfectly in every device which has an API level of greater than 11. but its not working in api level less than 11 .
Here is my DatePickerDialog
package com.rh.bookmany.fragments;
import java.util.Calendar;
import com.rh.bookmany.interfaces.OnShowDateSelectedListener;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.widget.DatePicker;
//DatePicker
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
int max;
OnShowDateSelectedListener onShowDateSelected;
public DatePickerFragment(,int max) {
this.max = max;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
final Calendar c2 = Calendar.getInstance();
c2.add(Calendar.DATE, max);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// new instance of DatePickerDialog
DatePickerDialog dd = new DatePickerDialog(getActivity(),this,year, month, day);
dd.getDatePicker().setMinDate(c.getTimeInMillis()); //ERROR HERE
dd.getDatePicker().setMaxDate(c2.getTimeInMillis()); //ERROR HERE
/*
Lint says:
Call requires API level 11 (current min is 8): android.app.DatePickerDialog#getDatePicker
Call requires API level 11 (current min is 8): android.widget.DatePicker#setMinDate
Call requires API level 11 (current min is 8): android.widget.DatePicker#setMaxDate
*/
return dd;
}
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
Log.d("X","Date Picked:"+year+"-"+month+"-"+day);
}
}
and I am calling it like this
// Showing Date Picker with 4 days after today
DialogFragment datePickerFragment = new DatePickerFragment(4);
datePickerFragment.show(getActivity().getSupportFragmentManager(),"datepicker");
and the lint says like this
Call requires API level 11 (current min is 8): android.app.DatePickerDialog#getDatePicker
Call requires API level 11 (current min is 8): android.widget.DatePicker#setMinDate
Call requires API level 11 (current min is 8): android.widget.DatePicker#setMaxDate
My question is :
Is it possible to work those three methods in api level less than 11 (getDatePicker(),setMinDate(),setMaxDate()).
If yes how? else - is there any alternatives ??