我正在尝试使用自定义datePicker date picker
但是在片段内的根布局膨胀时我遇到了这个错误:
public void button_click(View view) {
// Create the dialog
final Dialog mDateTimeDialog = new Dialog(view.getContext());
// Inflate the root layout
final RelativeLayout mDateTimeDialogView = (RelativeLayout)getLayoutInflater()
.inflate(R.layout.datepick,false);
.....
我该如何解决这个问题?
修改
此代码有效:
// Inflate the root layout
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater.inflate(R.layout.datepick, null);
答案 0 :(得分:2)
如果您有任何父视图获取作为膨胀的参数。 eq:view.inflate(int resource,ViewGroup root,boolean attachToRoot);
view.inflate(int resource, parentView, false);