本文介绍了Android的 - 在datepickerdialog隐藏日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何隐藏/在datepickerdialog删除日期字段。其实我的要求是要使用本机日期选取器对话框,但它显示了日,月,年。但按我的要求,我只需要月份和年份。所以我要隐藏或删除该视图日字段。
任何帮助将非常有用。
解决方案
私人DatePickerDialog createDialogWithoutDateField(){
DatePickerDialog DPD =新DatePickerDialog(_activity,ExpiryDateSetListener,cyear,cmonth,cday);
尝试{
现场[] datePickerDialogFields = dpd.getClass()getDeclaredFields()。
对于(场datePickerDialogField:datePickerDialogFields){
如果(datePickerDialogField.getName()。等于(mDatePicker)){
datePickerDialogField.setAccessible(真正的);
DatePicker的日期选择器=(DatePicker的)datePickerDialogField.get(DPD);
字段datePickerFields [] = datePickerDialogField.getType()getDeclaredFields()。
对于(场datePickerField:datePickerFields){
如果(mDayPicker.equals(datePickerField.getName())){
datePickerField.setAccessible(真正的);
对象dayPicker =新的对象();
dayPicker = datePickerField.get(日期选择器);
((查看)dayPicker).setVisibility(View.GONE);
}
}
}
}
}赶上(例外前){
}
返回DPD;
}
使用上述code隐藏在DatePickerDialog日字段。
请参阅此 LINK
How to hide/remove date field in datepickerdialog.Actually my requirement is to use the native date picker dialog but it shows up with day, month, and year. But as per my requirement i need only month and year. So i want to hide or remove the day field from the view.
Any help will be much usefull.
解决方案
Private DatePickerDialog createDialogWithoutDateField(){
DatePickerDialog dpd = new DatePickerDialog(_activity, ExpiryDateSetListener,cyear,cmonth, cday);
try{
Field[] datePickerDialogFields = dpd.getClass().getDeclaredFields();
for (Field datePickerDialogField : datePickerDialogFields) {
if (datePickerDialogField.getName().equals("mDatePicker")) {
datePickerDialogField.setAccessible(true);
DatePicker datePicker = (DatePicker) datePickerDialogField.get(dpd);
Field datePickerFields[] = datePickerDialogField.getType().getDeclaredFields();
for (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;
}
Use the above code for hiding the day field in DatePickerDialog.
Refer this LINK
这篇关于Android的 - 在datepickerdialog隐藏日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!