【问题标题】:The method getLayoutInflater(Bundle) in the type Fragment is not applicable for the arguments ()Fragment 类型中的方法 getLayoutInflater(Bundle) 不适用于 arguments()
【发布时间】:2013-05-16 10:24:57
【问题描述】:

我正在尝试使用自定义 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);

【问题讨论】:

    标签: android android-fragments layout-inflater


    【解决方案1】:

    如果你有任何父视图 get 作为 inflate 的参数。 eq: view.inflate(int resource, ViewGroup root, boolean attachToRoot);

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

    【讨论】:

    • 感谢@Hosein,有什么方法可以获取父视图吗?
    • 我试过这个:final RelativeLayout mDateTimeDialogView = view.inflate(R.layout.datepick, view.getParent(), false);但出现此错误:View 类型中的方法 inflate(Context, int, ViewGroup) 不适用于参数 (int, ViewParent, boolean)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2015-09-12
    相关资源
    最近更新 更多