spacitron
spacitron

Reputation: 2183

How to keep track of which view is being displayed in a view flipper?

I'm trying to create a custom implementation of ViewFlipper but I'm finding it rather confusing to keep track of which view is being called. I have put a log in my class like below:

@Override
public void setDisplayedChild(int childIndex) {
    Log.d("hello", childIndex);
}

I added 4 child views to test the class. Now, when showNext() is called things are all fine and the following result occurs: 1; 2; 3; 4; 1; 2... When I call showPrevious() however thing go a bit wrong and the result I get is: -1; 2; 1; 0; -1; 2...

Why do the sequences start and end with different numbers?

Upvotes: 0

Views: 71

Answers (1)

s.d
s.d

Reputation: 29436

ViewFlipper inherits from ViewAnimator:

getCurrentView() : Returns the View corresponding to the currently displayed child.

getDisplayedChild() : Returns the index of the currently displayed child view.

Also, before setting the child index, check if it is valid.

Upvotes: 1

Related Questions