Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:27:21+00:00 2026-05-29T20:27:21+00:00

In Stackview, it seems that OnItemSelectedListener (from superclass AdapterView) is never called… How can

  • 0

In Stackview, it seems that OnItemSelectedListener (from superclass
“AdapterView”) is never called…
How can I trigger some event when the view on top of the stack is
changed by the user ?

I want to display some text to show the position of the current item
inside the stack, so I need to find a way to update the textview when the user browses through the stack.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:27:25+00:00Added an answer on May 29, 2026 at 8:27 pm

    What i have done is writing a new class extending StackView and writing some code to get the OnItemSelected logics works. When the onTouchEvent gives me a MotionEvent.getAction() == ACTION_UP, i start a Thread that calls himself ’till the StackView.getDisplayedChild() changes. When it changes, i start the OnItemSelected logic, so i can always get the first displayed child.

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == MotionEvent.ACTION_UP && this.getAdapter() != null) {
            mPreviousSelection = this.getDisplayedChild();
            post(mSelectingThread);
        }
        return super.onTouchEvent(motionEvent);
    }
    

    This thread cycles himself untill he gets the new displayedChild:

    private class SelectingThread implements Runnable {
        CustomStackView mStackView;
    
        public SelectingThread(CustomStackView stackView) {
            this.mStackView = stackView;
        }
    
        @Override
        public void run() {
            if(mStackView.getAdapter() != null) {
                if (mPreviousSelection == CustomStackView.this.getDisplayedChild()) {
                    mThisOnItemSelectedListener.onItemSelected(mStackView, mStackView.getAdapter().getView(mPreviousSelection, null, mStackView),
                        mStackView.mPreviousSelection, mStackView.getAdapter().getItemId(mPreviousSelection));
                    return;
                } else {
                    mPreviousSelection = mStackView.getDisplayedChild();
                    mStackView.post(this);
                }
            }
        }
    }
    

    This Listener instead sets the Selected flag to true after deselecting them all.

    private class StackViewOnItemSelectedListener implements OnItemSelectedListener {
    
        CustomStackView mStackView;
    
        public StackViewOnItemSelectedListener(CustomStackView stackView) {
            this.mStackView = stackView;
        }
    
        @Override
        public void onItemSelected(AdapterView<?> parent, View selectedView, int position, long id) {
            deselectAll();
            if (mStackView.getAdapter() != null) {
                if (mOnItemSelectedListener != null) {
                    mStackView.mOnItemSelectedListener.onItemSelected(parent, selectedView, position, id);
                }
                mStackView.getAdapter().getView(position, null, mStackView).setSelected(true);
            }
        }
    
        private void deselectAll() {
            if (mStackView.getAdapter() != null) {
                int adapterSize = mStackView.getAdapter().getCount();
                for (int i = 0; i < adapterSize; i++) {
                    mStackView.getAdapter().getView(i, null, mStackView).setSelected(false);
                }
            }
        }
    
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            if (mStackView.getAdapter() != null) {
                if (mOnItemSelectedListener != null) {
                    mStackView.mOnItemSelectedListener.onNothingSelected(parent);
                }
                deselectAll();
            }
        }
    }
    

    I’ve tested it a little and it works..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an application that displays the Stack View as shown above
In my iPhone application I've set up a default, blank view called Main View
I need to implement a widget that uses Stackview which is supported on sdk
I have an AppWidget that has a StackView contained within it. Along with the
I'm looking to create some widgets for Honeycomb, and I've successfully created a StackView
My main view PlayGameViewController has a subview (actually 2 of them) called CardViewController. CardViewController
Here is some of the code from one of my classes, I was wondering
I'm sharing some variables accross activities by using a class like this : public
I've a Java Stack created and some custom objects added to it. These objects
I'm working a personal project that's going to include a home-screen widget updated with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.