In my main view, I have:
public class PlayersActivity extends Activity { ViewFlipper flipper; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.playercontainer); flipper = (ViewFlipper) findViewById(R.id.flipper); } }
with this view:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent"> <include android:id="@+id/first" layout="@layout/first" /> <include android:id="@+id/second" layout="@layout/playerdetailsview" /> </ViewFlipper>
It displays the first view correctly but I want it to be connected to a java class so I created an FirstActivity class where I can control all my components in the first view but how do I attach the first.xml layout with the FirstActivity java class ?
Use the <include> tag However, if you want to override layout attributes using the <include> tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.
To do so, select a res/layout folder in our project and click the button for creating a new file. In the File field enter the name of the file: myscreen. xml and click Finish. New layout file should open instantly.
You can use as many layouts as possible for a single activity but obviously not simultaneously. You can use something like: if (Case_A) setContentView(R. layout.
Say your new xml file is foo.xml
:
foo.xml
file in your res/layout
directory.setContentView(R.layout.foo);
See also the topic on declaring layout.
1) Create an xml file (say foo.xml
).
2) Put foo.xml
in res/layout
directory.
3) Edit foo.xml
and put some android layout code and save it. e.g.,
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="match_parent" android:layout_height="wrap_content"></ViewFlipper> </LinearLayout>
4) In your new activity class put
setContentView(R.layout.foo);
For creating an activity see this answer
I guess the problem with your xml file is that you had not specified any layout for the activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With