Posted by & filed under Android, Java, Tipps & Tricks.

Ever wanted to use a StackView and have a X out of Y counter to show the number of the currently selected View. Nope. Not possible. I don’t know what the folks at google thought but neither the StackView, nor the AdapterViewAnimator call the OnItemSelectedListener as soon as the user selects another View from the StackView.

Fortunately I found an easy to use solution. View the code after the break!

You can now add an OnItemSelectedListener to the StackViewAdv and get the index of the currently selected View. Please note that you only get the index, as i pass null as the child-View.

Unfortunately this.getCurrentView() doesn’t work here because it returns a inner class of StackView, not the actual View. If you find a way please let me know.

Comments are closed.