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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:30:51+00:00 2026-06-01T10:30:51+00:00

Ok so I am working on an android app and I have implanted spinners…

  • 0

Ok so I am working on an android app and I have implanted spinners… I have a total of four spinners and I have learned that if the spinner reads the options from the strings it has a defined number for the selection(i.e the first option is “0” next is “1” and so on)

I have the following code for the spinner

        Spinner a = (Spinner) findViewById(R.id.spinner1);
    a.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView adapter, View v, int a,
                long lng) {
            // do something here
            Toast.makeText(adapter.getContext(), "You selected: " + a,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView arg0) {
            // do something else
        }
    });

and another one but with the int “b”

but later on in the same class I want to use some maths to get e=a,b (i.e if a=6 and b=5 e=65, or a=4 and b=3 e=43)
This is easily done by executing

int e=a*10+b;

The problem is I want to display this when you press a button, so I have the following code

public void Calc(View v) {
    int e = a * 10 + b;
    Toast.makeText(this, "Value: " + e, Toast.LENGTH_LONG).show();
}

but results in the error “”a” & “b” cannot be resolved to a variable”
why is this and how can I create a button that will be able to read these variables?

  • 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-01T10:30:52+00:00Added an answer on June 1, 2026 at 10:30 am

    It’s a matter of scope, since you declared a in a method, it is not accesible outside of the method. Declare the spinner as class members, and only assign it in the method:

    class scope:

    Spinner a;
    

    In the method:

    a = (Spinner) findViewById(R.id.spinner1);
    

    Then:

    public void Calc(View v) {
        int itemA, itemB;
        itemA = a.getSelectedItemPosition();
        itemB = b.getSelectedItemPosition();
        int e = itemA * 10 + itemB;
        Toast.makeText(this, "Value: " + e, Toast.LENGTH_LONG).show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an android app that writes and reads .PNG files from sdcard.
I have an Android app that I had working a few months ago which
I am working on Android app and as part of that, I have to
I am working on an Android app that displays photos which are downloaded from
I am developing an android app in which I have 3 spinners populated from
I have a working Android tuner project app that I want to use as
I am working on an Android app and have a couple strings that I
I am working on an Android App that implements Flash Peer-assisted networking. I have
I am working on an android app and have to use remote database for
Working on an Android app with FB 4.6, I would like to have the

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.