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

The Archive Base Latest Questions

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

when the user enters a number in a edittext my app then creates and

  • 0

when the user enters a number in a edittext my app then creates and displays that many spinners. The user will then select an item from each spinner and then click a save button. I have looked on the internet but have been unable to find a way to retrieve the position from the spinners. Here is how I created the spinners:

//numStockTanks is the number of spinners to be created
numStockTanks = Integer.parseInt(numOfStockTanks.getText().toString());             
    // creates all the fields
    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> adapterStockTankSize2 = ArrayAdapter.createFromResource(
                this, R.array.StockTankSize, android.R.layout.simple_spinner_item);
        adapterStockTankSize2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapterStockTankSize2);
        spinner.setId(1000 + i);

        // 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
} // end getNumberCreateSpinner ()

I have attemped several different way to get the position of the spinners but I cant seem to figure it out. Here is what I currently have:

ArrayList<Integer> mArraySpinner = new ArrayList<Integer>();
for (int i = 0; i < numStockTanks; i++) {
           spinner = (Spinner) findViewById(1000 + i);
           if (spinner.getSelectedItemPosition() == 1) {
               mArraySpinner.add(100);
           } else if (spinner.getSelectedItemPosition() == 2) {
               mArraySpinner.add(200);
           } else if (spinner.getSelectedItemPosition() == 3) {
               mArraySpinner.add(210);
          } else if (spinner.getSelectedItemPosition() == 4) {
               mArraySpinner.add(295);
           } else if (spinner.getSelectedItemPosition() == 5) {
               mArraySpinner.add(400);
          } else mArraySpinner.add(0);
    } // end for statement

Thanks for your help

Edit:
Updated to my latest attempt after the first answer

Edit Edit:
When I debug the line “spinner = (Spinner) findViewById(1000 + i);” it says null so I know that I am not pointing to my spinner correctely this is what I need the help with

Edit: bump

  • 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:14:29+00:00Added an answer on June 8, 2026 at 10:14 pm

    I would set an onItemSelectedListener when you create the spinner (inside the loop where you create the spinner), and use that to set the value into an array that is a class field.

    mArraySpinner = new Array<Integer>[numStockTanks];
    for(int i = 1; i <= numStockTanks; i++) { 
    
          // code to set spinner adapter, etc.
    
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
           mArraySpinner[i] = spinner.getSelectedItemPosition();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The user enters a number in an EditText , the app then programmatically creates
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 14 edittext boxes that a user can change at will. When the
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,

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.