我试图显示一个只有月和年的日期选择器。
这是我的代码:
Calendar todayDate = Calendar.getInstance();
android.app.DatePickerDialog pickerDialog = new android.app.DatePickerDialog(
new ContextThemeWrapper(getContext(),
android.R.style.Theme_Holo_Light_Dialog_NoActionBar),
new android.app.DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
updateDobButtonWithValue(button, i, i1, i2, sdfdisplay, sdfvalue, valuechangecallback);
}
},
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
);
pickerDialog.getDatePicker().setMaxDate(todayDate.getTimeInMillis());
pickerDialog.getDatePicker().findViewById(getResources().getIdentifier("day","id","android")).setVisibility(View.GONE);
pickerDialog.show();
但问题是,当它到达这行代码时
。pickerDialog.getDatePicker()findViewById(getResources()则getIdentifier("天"" ID""机器人&#34))。setVisibility(查看。已废弃的);
它将返回错误
java.lang.NullPointerException:尝试调用虚方法' void android.view.View.setVisibility(int)'在空对象引用上
不幸的是,它适用于7.0以下的Android版本(Lollipop,marshmallow),但它在Android 7.0(Nougat)上无效。
有人能发现这个问题吗?感谢