TimePicker自定义布局,出现空指针异常
shaoguanglin opened this issue · comments
shaoguanglin commented
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setBackgroundColor(int)' on a null object reference
at com.bigkoo.pickerview.view.TimePickerView.initView(TimePickerView.java:80)
at com.bigkoo.pickerview.view.TimePickerView.(TimePickerView.java:34)
at com.bigkoo.pickerview.builder.TimePickerBuilder.build(TimePickerBuilder.java:312)
设置的代码如下:
pvTime=new TimePickerBuilder(getActivity(), new OnTimeSelectListener() {
@OverRide
public void onTimeSelect(Date date, View v) {
onTimeSet(date);
}
}).setOutSideCancelable(true)//点击屏幕,点在控件外部范围时,是否取消显示
.isCyclic(false)//是否循环滚动
.setTextColorCenter(Color.BLACK)
.setContentTextSize(16)
.setType(new boolean[]{true,true,true,true,true,false})
.setRangDate(startDate,endDate)//起始终止年月日设定
.setLabel("","","","","","")//默认设置为年月日时分秒
.isCenterLabel(false) //是否只显示中间选中项的label文字,false则每项item全部都带有label。
.isDialog(false)//是否显示为对话框样式
.setDecorView(mContainer)//getContanir()
.setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {
@Override
public void customLayout(View v) {
TextView tv_cancle=v.findViewById(R.id.iv_cancel);
TextView tv_ok=v.findViewById(R.id.tv_finish);
tv_cancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pvTime.dismiss();
}
});
tv_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pvTime.returnData();
pvTime.dismiss();
}
});
}
}).build();