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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:37:54+00:00 2026-06-15T22:37:54+00:00

When I select an option It opens an activity but when i finish with

  • 0

When I select an option It opens an activity but when i finish with that activity and I returnt ot the spinner activity, the spinner is still open.

How can I dismiss it right after I select an item?

sp.setOnItemSelectedListener(new OnItemSelectedListener() {
            boolean firstPop =true;
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int pos, long arg3) {
                if (!firstPop) {

                    doMyLogic();
                    sp.????
                }
                firstPop = false;

            }

edit full code

public void showDropDownDialogue() {

        String[] s = getResources().getStringArray(R.array.cities);
        final ArrayAdapter<String> adp = new ArrayAdapter<String>(
                MainActivity.this, android.R.layout.simple_spinner_item, s);

        final Spinner sp = new Spinner(MainActivity.this);
        sp.setPadding(5, 5, 5, 5);
        sp.setLayoutParams(new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        sp.setAdapter(adp);


        sp.setOnItemSelectedListener(new OnItemSelectedListener() {
            boolean firstPop =true;

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int pos, long arg3) {
                if (!firstPop) {
                    editor.putInt("city_id", pos);
                    editor.commit();
                    Intent stationsIntent = new Intent(MainActivity.this,
                    StationsActivity.class);
                    startActivity(stationsIntent);


                }
                firstPop = false;

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setView(sp);
        builder.create().show();

    }
  • 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-15T22:37:56+00:00Added an answer on June 15, 2026 at 10:37 pm

    Its the dialog that needs to be closed and not the spinner. SO declare AlertDialog as a field

    and change dialog show like below.

    builder.setView(sp);
    dialog = builder.create();
    dialog.show();
    

    And in onItemSelected add

    dialog.dismiss();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a select option list with values in it. But as with
When my app first opens my first activity that is presented to the user
In my application the user opens up a grid and selects an option. After
I need an Open Dialog File Chooser that opens files for reading only. I
If we open IIS 5 Manager and right click on virtual directory --> select
I'm trying to style a select option list using CSS. I want more padding
Is there a style for a select option's selected color? For example: <HTML> <BODY>
How should I understand $(select option:selected) in the following code ? (taken from here
I'm trying to re-append a removed option to the appropriate select option menu. I
I'm passing expiry parameters with a form 'select' option. Works in all browsers except

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.