0

Is it possible to get array of views from onItemSelected()? because I need to set animation for current view and clear the animation from other views, is it possible?

        @Override
        public void onItemSelected(AdapterView<?> adV, View view, int currentIndex, long l) 
        {

                view.startAnimation(AnimationUtils.loadAnimation(currentContext, R.anim.scale_anim));
                adV[currentIndex + 1].clearAnimation();
                adV[currentIndex - 1].clearAnimation();

        }
6
  • 2
    catch NullPointerException? Are you serious? Commented Feb 22, 2013 at 14:33
  • @m0skit0 yup, NullPointerException happened when I change my device orientation from startAnimation() method! Commented Feb 22, 2013 at 14:37
  • 1
    You should fix your code, not catch an NPE. Commented Feb 22, 2013 at 14:38
  • Your question is not clear enough. What Views you want in the array? Commented Feb 22, 2013 at 14:42
  • @m0skit0 Forgot the views, I want to clear all animation from the views expect the current view. Commented Feb 22, 2013 at 14:43

1 Answer 1

2

You could iterate over the children of the AdapterView like this:

int count = adV.getChildCount();
for (int i = 0; i < count; i++) {
    View v = adV.getChildAt(i);
    view.clearAnimation();
}

Of course you would need to check also if the view is the current one and skip it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Work like a charm.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.