嗨,有没有正确的方法可以在datepickerdialog中隐藏日期选择器?我使用的是原生的android datepickerdialog而不是自定义的datepickerdialog。希望有人可以提供帮助。
以下是我的datepickerdialog代码:
Button.OnClickListener monthOnClickListener
= new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
DialogFragment newFragment = new SelectDateFragment();
newFragment.show(getFragmentManager(), "DatePicker");
}
};
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
public void onDateSet(DatePicker view, int yy, int mm, int dd) {
String year=yy+"", month, day;
mm = mm+1;
if (dd==1 || dd==2 || dd==3 || dd==4 || dd==5 || dd==6 || dd==7 || dd==8 || dd==9)
day = "0"+ dd;
else
day = dd + "";
if (mm==1 || mm==2 || mm==3 || mm==4 || mm==5 || mm==6 || mm==7 || mm==8 || mm==9)
month = "0"+ mm;
else
month = mm + "";
}
}
我有谷歌隐藏日期选择器的方式但它似乎没有任何影响。以下是我尝试过的代码。
public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dpd = new DatePickerDialog(getActivity(), this,yy,mm, dd);
try{
java.lang.reflect.Field[] datePickerDialogFields = dpd.getClass().getDeclaredFields();
for (java.lang.reflect.Field datePickerDialogField : datePickerDialogFields) {
if (datePickerDialogField.getName().equals("mDatePicker")) {
datePickerDialogField.setAccessible(true);
DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd);
java.lang.reflect.Field[] datePickerFields = datePickerDialogField.getType().getDeclaredFields();
for (java.lang.reflect.Field datePickerField : datePickerFields) {
if ("mDayPicker".equals(datePickerField.getName())) {
datePickerField.setAccessible(true);
Object dayPicker = new Object();
dayPicker = datePickerField.get(datePicker);
((View) dayPicker).setVisibility(View.GONE);
}
}
}
}
}catch(Exception ex){
}
return dpd;
//return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}
答案 0 :(得分:0)
与“DatePicker”一起使用也使用“mDay Spinner”这个