不能给FrameLayout充气

时间:2013-12-06 08:44:26

标签: android android-framelayout android-inflate

我正在尝试这个问题答案的代码:dynamically add and remove view to viewpager

我复制了代码但是以下行的inflater无法解析。

FrameLayout v0 = (FrameLayout) inflater.inflate (R.layout.fragment_schema, null);

这是我的xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
</FrameLayout>

1 个答案:

答案 0 :(得分:2)

你的inflater无法解决?这意味着你没有在代码中初始化甚至声明变量,你从另一个问题复制的代码说“做其他初始化”,这是其中一个没有显示的。你可以这样做:

LayoutInflater inflater = (LayoutInflater)context.getSystemService
      (Context.LAYOUT_INFLATER_SERVICE);
相关问题