0

I have a problem.

I slip my Screen in two areas with 2 ViewStubs.

But if i inflated the ViewStubs they are no more accessible and i can't inflate an other View within this ViewStub.

So what is an alternative to use these kind containers.

Here some Code. You all love Code:

    ViewStub contentSpace = (ViewStub) findViewById(R.id.ContentSpace);       
    contentSpace.setLayoutResource(R.layout.view1);
    contentSpace.inflate();
    contentSpace.setInflatedId(R.id.Content);
    RelativeLayout content = (RelativeLayout) findViewById(R.id.Content);

    contentSpace.setLayoutResource(R.layout.view1); //crash
    contentSpace.inflate();
passsy
  • 5,162
  • 4
  • 39
  • 65
  • could this help? http://stackoverflow.com/questions/5342121/inflate-a-view-layout-into-another-layout/5343733#5343733 – bigstones May 05 '11 at 19:43

2 Answers2

2

It seems like ViewStub can't be re-inflated. It is designed to be inflated just once, then it is removed from the View hierarchy. More details here: https://stackoverflow.com/a/11579271/752781

Community
  • 1
  • 1
pandre
  • 6,685
  • 7
  • 42
  • 50
-1

Here my Solution

rootLayout is a linear Layout where may ViewStubs were located.

    rootLayout.removeView(contentLayout);
    inflater.inflate(R.id.view1, rootLayout);
    contentLayout = findViewById(R.id.contentLayout);

view1:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"    
        android:id="@+id/contentLayout">
[...]
passsy
  • 5,162
  • 4
  • 39
  • 65