Fragment类中的getLayoutInflater(Bundle)方法不适用于()参数。

4

我正在尝试使用自定义日期选择器日期选择器

但是在片段中填充根布局时,我遇到了以下错误:

 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);
1个回答

2

如果您在inflate方法中的参数中有任何父级视图需要传入,例如:view.inflate(int resource, ViewGroup root, boolean attachToRoot);

view.inflate(int resource, parentView, false);

谢谢@Hosein,有没有获取父视图的方法? - kyokotsu
我尝试了这个: final RelativeLayout mDateTimeDialogView = view.inflate(R.layout.datepick, view.getParent(), false); 但是出现了这个错误: 在 View 类型中,inflate(Context, int, ViewGroup) 方法不适用于参数 (int, ViewParent, boolean)。 - kyokotsu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接