1
我想在我的應用程序中使用DatePickerDialog。它在每個API級別大於11的設備上都能正常工作,但它在api級別上的工作不到11級。api級別小於11的DatePickerDialog
這裏是我的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);
}
}
,我叫它這樣
// Showing Date Picker with 4 days after today
DialogFragment datePickerFragment = new DatePickerFragment(4);
datePickerFragment.show(getActivity().getSupportFragmentManager(),"datepicker");
和皮棉說,像這樣
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
我的問題是:
它是位置嗎?能夠在api級別工作這三個方法小於11(getDatePicker(),setMinDate(),setMaxDate())。
如果是的話如何?其他 - 有沒有其他的選擇?
http://stackoverflow.com/questions/10836679/android-datepicker-min- MAX-日期前-API級-11 – PPD 2015-01-21 07:06:48