Reputation: 5440
I have a viewflipper and two buttons "next" and "previous" outside the viewflipper. I want viewflipper to show next background on clicking "next" and previous background on clicking "previous". How can I do that?
Upvotes: 2
Views: 6931
Reputation: 11786
you need to do the following:
nextButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
viewFlipper.showNext();
}
});
}
and the same for the previous button.
Upvotes: 2
Reputation: 10349
There are two techniques to achieve your requirements.
1. Use showPrevious and showNext methods of ViewFlipper class. One thing you have to know about these methods is by calling any method continuously, it will start displaying it's children in ascending order for showNext and descending order for showPrevious.
Example : View flipper has 4 children say 0, 1, 2, 3. Initially it will display first item i.e., child 0. Now if you called showNext 6 times continuously, it starts displaying 1, 2, 3, 0, 1, 2. So finally it will display child 2. Same procedure in descending order for shoePrevious also.
2. Use setDisplayedChild method to display a particular child included in the ViewFlipper.
Example: The view flipper may as below in XML layout file
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include android:id="@+id/first" layout="@layout/first_view" />
<include android:id="@+id/second" layout="@layout/second_view" />
</ViewFlipper>
To display first child you can use setDisplayedChild in two ways.
call setDisplayedChild(R.id.first);
or setDisplayedChild(0);
means you can use Id of child in ViewFlipper or position of child in ViewFlipper.
So depending on actual requirements, decide which method is appropriate.
I hope you understand this.
Upvotes: 6
Reputation: 4503
You can call yourViewFlipper.showNext()
or yourViewFlipper.showPrevious()
in your next and previous button click handlers.
Upvotes: 0
Reputation: 4926
By viewFlipper.showPrevious() and viewFlipper.showNext() you can do this .
Upvotes: 2