How to connect a layout view with an activity

android, android-activity, layout

Solution

Say your new xml file is `foo.xml`:

- Put `foo.xml` file in your `res/layout` directory.

- In your new class use `setContentView(R.layout.foo);`

- Specify your new class in your manifest file.

See also the topic on declaring layout.

Problem

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 ?

Original source

Related problems