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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:10:45+00:00 2026-06-14T15:10:45+00:00

I’m trying to set a spinner item Equal to a Specific Integer . I’m

  • 0

I’m trying to set a spinner item Equal to a Specific Integer. I’m using onItemSelected to try and accomplish this, but the problem is, I need the integer that is set for the item selected to be multiplied by another EditText in the same row with the Integer. To mix things up a bit, all of my EditTexts in the row that I am trying to mulitply by, is referenced to a list then iterated so that I can add them all up. How do I get each EditText in the same row as the Selected Spinner Item(which has an Int Value) to multiply by the Selected Spinner Item? Here’s what I have so far…. Sorry for the mess!

    int count = 1;
double gradeValue;
List<EditText> allEd = new ArrayList<EditText>();
List<Spinner> allSp = new ArrayList<Spinner>();


@SuppressWarnings("deprecation")
public void onClick(View v) {
    TableLayout tableLayout1 = (TableLayout) findViewById(R.id.tableLayout1);

    switch(v.getId()){
    case R.id.button1:
        if(count != 16){
            count++;

            // Create the row only when the add button is clicked
            TableRow tempRow = new TableRow(MainActivity.this);
            EditText tempText1 = new EditText(MainActivity.this);
            EditText tempText2 = new EditText(MainActivity.this);
            TextView tempTextView = new TextView(MainActivity.this);
            Spinner spinnerTemp = new Spinner(MainActivity.this);
            EditText editText1 = (EditText) findViewById(R.id.editText1);
            EditText editText2 = (EditText) findViewById(R.id.editText2);
            TextView textView3 = (TextView) findViewById(R.id.textView3);
            Spinner s = (Spinner) findViewById(R.id.spinner1);
            tempTextView.setText(count + ".");

            tempRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            tempText1.setLayoutParams(editText1.getLayoutParams());
            tempText2.setLayoutParams(editText2.getLayoutParams());
            tempTextView.setLayoutParams(textView3.getLayoutParams());
            tempText1.setInputType(InputType.TYPE_CLASS_TEXT);
            tempText2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            tempText2.setId(count);
            spinnerTemp.setLayoutParams(s.getLayoutParams());
            spinnerTemp.setId(count);
            String options[] = { "A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F" };

            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, options);
            spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
            spinnerTemp.setAdapter(spinnerArrayAdapter);

            allEd.add(tempText2);
            allEd.add(editText2);
            allSp.add(spinnerTemp);

            tempRow.addView(tempTextView);
            tempRow.addView(tempText1);
            tempRow.addView(tempText2);
            tempRow.addView(spinnerTemp);
            tableLayout1.addView(tempRow);
        } 
        }
        break;
    case R.id.button2:
        if(count != 1){
            count--;
            tableLayout1.removeView(tableLayout1.getChildAt(count));
        }

        break;
    case R.id.button3:
        int calculation = 0;
        double spinnerChoice = 0;
        for(int i = 0; i < allEd.size(); i++) {
            EditText totalUnits = allEd.get(i);
            try {
            int units = Integer.parseInt(totalUnits.getText().toString());

            calculation += units;
            }catch (Exception e) {
                //ignore
            }

        for(int j = 0; j < allSp.size(); j++) {
            Spinner gradeTotal = allSp.get(j);
            try {
            int grades = gradeTotal.getCount();

            }catch (Exception e) {
                //ignore
            }

        }
    }
    }

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    if (pos == 0){
        //A+
        gradeValue = 4.0;
    } else if (pos == 1){
        //A
        gradeValue = 4.0;
    } else if (pos == 2){
        //A-
        gradeValue = 3.7;
    } else if (pos == 3){
        //B+
        gradeValue = 3.3;
    } else if (pos == 4){
        //B
        gradeValue = 3.0;
    } else if (pos == 5){
        //B-
        gradeValue = 2.7;
    } else if (pos == 6){
        //C+
        gradeValue = 2.3;
    } else if (pos == 7){
        //C
        gradeValue = 2.0;
    } else if (pos == 8){
        //C-
        gradeValue = 1.7;
    } else if (pos == 9){
        //D+
        gradeValue = 1.3;
    } else if (pos == 10){
        //D
        gradeValue = 1.0;
    } else if (pos == 11){
        //D-
        gradeValue = 0.7;
    } else if (pos == 12){
        //F
        gradeValue = 0.0;
    }
}
}
  • 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-14T15:10:46+00:00Added an answer on June 14, 2026 at 3:10 pm

    this looks harder than it should be cause you’re using a table layout. If all your rows are similar and it isn’t detrimental to your design, perhaps you might consider using a listview. then you could refer to things on the same row, simply by their position – conveniently supplied as a parameter.

    But since you have it like this, you can get the index of the selected spinner item in it’s position in the arraylist. which you can then refer to EditText arraylist. Off the top of my head, I’m thinking that you do a setTag() to your selected spinner items as a label. Then you loop through looking for the tag and doing something if it exists. Here is what i came up with. notice that i changed your onitemselected method to a method returning a double as i find that more useful for this kind of task:

        private double calcGradeValue (int pos) {
             if (pos == 0){
                 //A+
                 gradeValue = 4.0;
             } else if (pos == 1){
                 //A
                 gradeValue = 4.0;
             } else if (pos == 2){
                 //A-
                 gradeValue = 3.7;
             } else if (pos == 3){
                 //B+
                 gradeValue = 3.3;
             } else if (pos == 4){
                 //B
                 gradeValue = 3.0;
             } else if (pos == 5){
                 //B-
                 gradeValue = 2.7;
             } else if (pos == 6){
                 //C+
                 gradeValue = 2.3;
             } else if (pos == 7){
                 //C
                 gradeValue = 2.0;
             } else if (pos == 8){
                 //C-
                 gradeValue = 1.7;
             } else if (pos == 9){
                 //D+
                 gradeValue = 1.3;
             } else if (pos == 10){
                 //D
                 gradeValue = 1.0;
             } else if (pos == 11){
                 //D-
                 gradeValue = 0.7;
             } else if (pos == 12){
                 //F
                 gradeValue = 0.0;
             }
            return gradeValue;
        }
    
        public void spinnerLoop() {
            for(int i = 0; i < allSp.size(); i++) {
                if (allSp.get(i).getTag().toString() == "TAGGED!") {
                    double gradeValue = calcGradeValue(allSp.get(i).getSelectedItemPosition()); 
                    double calculation = (gradeValue) * (Integer.parseInt(allEd.get(i).getText().toString()));
    //              do something with your calculation double
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.