Search code examples
androidandroid-layoutviewflipper

ViewFlipper with onclick


I'm doing a layout where different content will be display in one place.

enter image description here

Example: When click on button 1 the context will display in box A and if I click on the next button4 the contant will also display in box a

I am using the ViewFlipper for this below is the xml code

<ViewFlipper
            android:id="@+id/view_flipper"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="6dip" >

            <include
            android:id="@+id/a1"
            layout="@layout/a1" />

        <include
            android:id="@+id/a2"
            layout="@layout/a2" />

        <include
            android:id="@+id/a3"
            layout="@layout/a3" />

        </ViewFlipper>

below is the onclick listener I use

a1.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {

            viewFlipper.bringChildToFront(myFragmentView.findViewById(R.id.ghfristd));

        }
    });

but nothing seen to appear.

if Viewflipper is not adviseable to use in the example image i provided what will be adviseable. any suggestion is welcome


Solution

  • If you want the ViewFlipper to show a particular child view then you should use

    viewFlipper.setDisplayedChild(index);
    

    Where index is the child's index.