开发者

Changing views with ViewFlipper Android

I need a little help.I'm using a ViewFlipper to change views in TabActivity but not really sure how to do it.Here is my code :

MainActivity.class

public class Collections extends Activity implements OnClickListener {

    ViewFlipper vFlip;
    Button genre, recommended, soon;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.collections_layout);

        vFlip = (ViewFlipper) findViewById(R.id.tags_flipper);

        genre = (Button) findViewById(R.id.genre_btn);
        genre.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vFlip.getCurrentView();
                }

            });
        recommended = (Button) findViewById(R.id.recom_btn);
        recommended.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vFlip.getCurrentView();
                }

            });
        soon = (Button) findViewById(R.id.soon_btn);
        soon.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    vFlip.getCurrentView();
                }

            });
    }
}

I have three different xml, which I want to load with clicking the buttons.Here is the collection_layout.xml

Collection_layout.xml

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

            <LinearLayout
            android:id="@+id/actionbar"
            android:layout_width="fill_parent"
            android:layout_height="65px"
            android:background="@drawable/p开发者_如何学JAVAink_bar"
            android:tileMode="repeat"
            android:orientation="vertical">

                <ImageView 
                    android:src="@drawable/stampii_logo"
                    android:id="@+id/stampii_logo_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingTop="20px"/>

            </LinearLayout>

                <LinearLayout
                android:id="@+id/first_container"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">



                    <LinearLayout 
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="1"
                    android:background="#d229ce">


                    <Button
                        android:id="@+id/genre_btn"
                        android:text="By Genre"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="10dp" />

                    <Button
                        android:id="@+id/recom_btn"
                        android:text="Recommended"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="10dp" />

                    <Button
                        android:id="@+id/soon_btn"
                        android:text="Expect Soon!"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="10dp" />

                    </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/flip"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#FFFFFF" >

                <ViewFlipper 
                    android:id="@+id/tags_flipper"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <include android:id="@+id/genre" layout="@layout/by_genre" />
                    <include android:id="@+id/recom" layout="@layout/recommended" />
                    <include android:id="@+id/soon" layout="@layout/expect_soon" />
                </ViewFlipper>


        </LinearLayout>


</LinearLayout>

So how can i do that?Thanks a lot!


Use ViewFlipper.setDisplayedChild

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜