I am trying the code from the answer of this question: dynamically add and remove view to viewpager

I copied the code but inflater at the following line can't be resolved.

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

This is my xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
</FrameLayout>
有帮助吗?

解决方案

Your inflater cannot be resolved ? It means you have not initialized or even declared the variable in your code, the code you copied from the other question said "do other initialization", that was one of them that was not showed. You can do so like this :

LayoutInflater inflater = (LayoutInflater)context.getSystemService
      (Context.LAYOUT_INFLATER_SERVICE);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top