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 7808999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:17:58+00:00 2026-06-02T03:17:58+00:00

I have a Gallery which allows users to browse a gallery, select an image

  • 0

I have a Gallery which allows users to browse a gallery, select an image as their choice, and continue to browse the gallery without changing that selection. This works by using onItemSelected to see if the image they are selecting (ie, with a click) is the image already selected (by the gallery’s motion). So:

  1. User moves forward and back through Gallery.
  2. User decides on their favoured image and centres the Gallery on it.
  3. User clicks the image, it gets “selected” and is given a green border.
  4. User can continue to move forward and back in the Gallery, without the currently centred image automatically being “selected”.

This is fine. However, I am now trying to allow orientation changes while selecting an image, and what I have found is that onItemSelected is called on the Gallery after all the onConfigChanged code has executed.

So onConfigChange I set parameters (ie, what index the Gallery was on before orientation change), and then I call my initialiseUI method. This executes successfully and sets up everything it needs to, including positioning the Gallery at the same index it was positioned at before the orientation change. But then onItemSelected is called, on the centred image. This causes the centred image to be selected as their choice (green border etc), without the user clicking on it.

I have tried using a Boolean flag, “configIsChanging”, to only execute the onItemSelected code when configIsChanging is false. Unfortunately, this doesn’t seem to work, as onItemSelected is called after onConfigChange completes, and by that point the flag has been reset to false.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    configChanging = true; 

    tempConfigDisplayedIndex = mGallery.getSelectedItemPosition(); 

    super.onConfigurationChanged(newConfig);

    setContentView(R.layout.take_questionnaire);

    initialiseUI(); 
    configChanging = false; 
}

Has anyone had any experience with rogue onItemSelected events? Any ideas? I can post more code if required. Many thanks for any help.

  • 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-06-02T03:18:00+00:00Added an answer on June 2, 2026 at 3:18 am

    Following on from @Gabriel’s answer, I have solved the problem using the following code snippets. It’s slightly different from Gabriel’s code, and I’ve left out the bits no one else will care about 🙂

    @Override
    protected void onResume() {
        super.onResume();       
        configChanging = true; 
    }
    
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
    if (mAdapter.selectedIndex > -1) { 
        tempConfigSelectedIndex = mAdapter.selectedIndex;
    }
    
    super.onConfigurationChanged(newConfig);
    if (configChanging) {
        tempConfigDisplayedIndex = mGallery.getSelectedItemPosition(); 
    
        setContentView(R.layout.take_questionnaire);
    
        initialiseUI();
    }
    }
    
    @Override
    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    
    if (!configChanging){
        // code here to execute only when user clicks
    }
    configChanging = false; 
    // code here to execute when either user clicks OR config is changed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what i want to do is that i have a nice image Gallery which
I have a Gallery widget that allows a user to select from a variety
I have an HTML5 application that allows users to drag-n-drop an image to a
Hi I have a gallery in my app which shows the image in an
I have created a XML image gallery, which displays text in between each slide.
I have photo gallery code that does image re-sizing and thumbnail creation. I use
I've created a photo gallery that allows you to select multiple photos, but I've
I have an image gallery which loads a detail image, then draws a line
I have an image gallery for which I have configured an Imagecache preset. It's
I am developing a gallery which allows users to post photos, comments, vote and

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.