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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:54:48+00:00 2026-05-31T09:54:48+00:00

I have a simple spinner which has several number options. I want to just

  • 0

I have a simple spinner which has several number options. I want to just select a number and then it does some math to that number and outputs it in a text box. For some reason it’s only doing math on the 1st entry in the list and if you change it doesn’t update.

Any ideas?

package placeorder.com;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Spinner;
import android.widget.TextView;

public class Time extends Activity{ 

    double totalhours, cost;
    int price;
    TextView total, orderid;    

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.time);

        Spinner spinhours = (Spinner) findViewById(R.id.sp_hours);
        total = (TextView) findViewById(R.id.tv_total); 
        orderid = (TextView) findViewById(R.id.tv_orderid); 

        Random order = new Random();
        int randomorder = order.nextInt(9999);      
        order.nextInt(9999);                
        orderid.setText("Order ID: "+randomorder);      

        price = 5;                    
        String hours = spinhours.getSelectedItem().toString();
        totalhours = Integer.parseInt(hours);       
        cost = totalhours * price;              
        total.setText("£" + cost);              


    }



}
  • 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-05-31T09:54:49+00:00Added an answer on May 31, 2026 at 9:54 am

    You should add listener for spinner

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                     String str = (String) arg0.getSelectedItem();
    
                     outputTextview.setText(str);
    
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple class with width and height member fields which define number of
In my app I have a spinner in which the user selects a number.
I have spinner which I populate from SQLite database. But I want to populate
I have a simple Android Spinner which I fill with a two column list
I have a simple function that shows loading spinner while fetching data (usually takes
I want to use a Spinner that initially (when the user has not made
I have one spinner in which few values are there from strings.xml and I
I have an xml layout file which contains a few widgets including a Spinner
I have a spinner which is populated with Category objects that are retrieved from
I have spinner which populates from database: catSpinner = (Spinner) findViewById(R.id.spinner1); cursor = dataAdapter.getAllCategory();

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.