views:

230

answers:

1

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 ?

+1  A: 

Say your new xml file is foo.xml:

1) Put foo.xml file in your res/layout directory.
2) In your new class use setContentView(R.layout.foo); 3) Specify your new class in your manifest file.

See also the topic on declaring layout.

RickNotFred
Step 3 assumes your class is an activity.
RickNotFred
i did add <activity android:name="FirstActivity"></activity> in the application node (and followed the other steps to) but it still doesn't call the class do i define it right in the manifest ?
Andy Jacobs
You need to specify the fully qualified name. Assuming the class resides in the same package as your manifest, you can shorten by specifying as<activity android:name=".FirstActivity"></activity>(note the leading ".")
RickNotFred