-1

I'm trying to inflate a layout in another layout but it doesn't work... In my activity I show activity_serie.xml which is black, and then I try to inflate on image_item.xml which is white. But I never see image_item.xml.

public class Serie extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_serie);

    ViewPager mainLayout = (ViewPager) findViewById(R.id.serie_pager);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View menuLayout = inflater.inflate(R.layout.image_item, mainLayout, true);
}

@Override
protected void onResume() {
    super.onResume();
}}

The activity_serie.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000
    android:orientation="vertical" >

<android.support.v4.view.ViewPager
    android:id="@+id/serie_pager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

</RelativeLayout>

The image_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#FFFFFF"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</RelativeLayout>

Can someone tell me why? Thanks.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158

2 Answers2

0

findViewById(R.layout.activity_serie)

You should specify a view id here, not a layout name.

BladeCoder
  • 12,779
  • 3
  • 59
  • 51
  • When I add a RelativeLayout in the activity_serie.xml and then I inflate it, it work, but now I would work with a ViewPager and if I do that : ViewPager mainLayout = (ViewPager) findViewById(R.id.serie_pager); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View menuLayout = inflater.inflate(R.id.image_Display, mainLayout, true); It again doesn't work – Mickmouette Steack Jul 01 '15 at 15:05
  • You can't inflate a Layout manually directly into a ViewPager, they are not designed for that. You should use a PagerAdapter instead to populate it. – BladeCoder Jul 01 '15 at 23:51
0

Why you wanna do that? Just put both views into one xml, and set android:visibility="gone" for one element. Than you can address layout by id and change visibility as much as you want.

5er
  • 2,506
  • 7
  • 32
  • 49
  • I have changed the question, I do that because I want to use a ViewPager and set a PagerAdapter on it (to sweep some custom images with a finger), and the images can be update during the activity life. – Mickmouette Steack Jul 01 '15 at 15:55