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

  • Home
  • SEARCH
  • 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 8320093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:32:25+00:00 2026-06-08T22:32:25+00:00

The user enters a number in an EditText , the app then programmatically creates

  • 0

The user enters a number in an EditText, the app then programmatically creates that many spinners. I am having problems getting the positions of those spinners to save them when the user clicks the “save” button at the bottom of my UI.

When I try to get the position with: mArraySpinner.add(spinner.getSelectedItemPosition()); as seen below I have several empty locations in the array like the listener is firing on creation and then it will only save the last spinners position in the last element of the array.

Here is the code that I create the spinners with:

for(int i = 1; i <= numStockTanks; i++) {
        TableRow tR = new TableRow(this);
        // creates the textView
        tV1 = new TextView(this);
        tV1.setText("Stock Tank #" + i + " size: ");

        // add spinner to row
        spinner = new Spinner(this);
        ArrayAdapter<CharSequence> adapterStockTankSize = ArrayAdapter.createFromResource(
                this, R.array.StockTankSize, android.R.layout.simple_spinner_item);
        adapterStockTankSize.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapterStockTankSize);
        spinner.setTag(i + 600);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onNothingSelected(AdapterView<?> parent) {}
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                mArraySpinner.add(spinner.getSelectedItemPosition());
            }
        });

        // add the TextView and the editText to the new TableRow
        tR.addView(tV1);
        tR.addView(spinner);

        // add the TableRow to the TableLayout
        tL.addView(tR,new TableLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));    
    } // end for statement

thanks for your 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-08T22:32:26+00:00Added an answer on June 8, 2026 at 10:32 pm

    You are reassigning the spinner variable each time, but the onItemSelected method is using this variable. You need to redeclare this spinner variable each time so that the method is looking for a unique Spinner object.

    Change spinner = new Spinner(this); to final Spinner spinner = new Spinner(this);, and remove whatever declaration of spinner you have already.

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

Sidebar

Related Questions

when the user enters a number in a edittext my app then creates and
I have a button and an edittext. The user enters a number and then
the below code is working fine if the user enters the USN number that
I'm using an input that takes a number that a user enters and converts
Continuously ask the user to enter numbers until the user enters a number that
I have an activity that has an EditText. After a user enters their text,
In my app, the user has to enter a phone number in an EditText
I have a input type number. Once the user enters the number in that
I have a UI where the user enters a number into a text box,
I have a textbox where the user enters a number, but how can i

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.