How to inflate a layout properly using a nested ViewFlipper?

I had a simple main.xml layout that displayed only 2 views using the ViewFlipper shell. It worked (still works) perfectly using the following code:

setContentView(R.layout.main); mTV1 = (TextView) findViewById(R.id.textview01); mTV2 = (TextView) findViewById(R.id.textview02); mViewFlipper = (ViewFlipper)findViewById(R.id.flipper01); 

Now I want to add two buttons on top of the original views, similar to these :

 <LinearLayout android:id="@+id/linearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:id="@+id/linearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/button01" android:layout_height="wrap_content" android:text="Button 1" android:layout_width="0dip" android:layout_weight="1"></Button> <Button android:id="@+id/button02" android:layout_height="wrap_content" android:text="Button 2" android:layout_width="0dip" android:layout_weight="1"></Button> </LinearLayout> <RelativeLayout android:id="@+id/relativeLayout01" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1"> <ViewFlipper android:id="@+id/flipper01" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textview01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text" /> <TextView android:id="@+id/textview02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text2" /> </ViewFlipper> </RelativeLayout> </LinearLayout> 

My problem is that I intuitively changed the source code by inserting findViewById for the composite layout:

 setContentView(R.layout.main); mCompositeLayout = (LinearLayout) findViewById(R.id.linearLayout02); mTV1 = (TextView) findViewById(R.id.textview01); mTV2 = (TextView) findViewById(R.id.textview02); mViewFlipper = (ViewFlipper)findViewById(R.id.flipper01); 

But it displays exactly the same as before! As if I never added an extra linearLayout02 containing buttons.

What am I missing? What am I doing wrong?

+4
source share
1 answer

Try project-> clean (if you are using Eclipse) and make sure that you are editing the main.xml file on the right. Your code works, it doesn't matter CompositeLayout or ViewFlipper, buttons are drawn.

If you are sure that nothing is missing and the buttons are not drawn yet, try adding android: layout_weight to your new LinearLayout (containing the buttons). (For my Galaxy Nexus, everything is fine without weight, but the problem may occur due to fragmentation of the Android device)

+1
source

All Articles