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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:14:51+00:00 2026-05-31T20:14:51+00:00

I develop an application where spinner contains add, sub, mul & div… but the

  • 0

I develop an application where spinner contains add, sub, mul & div… but the result always gives zero. How I develop the app when button clicked the calculation solved depends upon the selected value of the spinner. The code is below::

public void Select(View view)
    {
        TextView txt1=(TextView)findViewById(R.id.editText1);
        TextView txt2=(TextView)findViewById(R.id.editText2);

        int x=Integer.parseInt(txt1.getText().toString());
        int y=Integer.parseInt(txt2.getText().toString());

        Spinner spin1=(Spinner)findViewById(R.id.spinner1);
        String spin_value= spin1.getItemAtPosition(spin1.getSelectedItemPosition()).toString();

        if(spin_value=="Add")
        {
            int z=x+y;
            String addvalue=String.valueOf(z);
            Toast.makeText(this, addvalue, Toast.LENGTH_LONG).show();
        }
        else if (spin_value=="Sub") 
        {
            int p=x-y;
            String subvalue=String.valueOf(p);
            Toast.makeText(this, subvalue, Toast.LENGTH_LONG).show();
        }
        else if (spin_value=="Mul") 
        {
            int k=x*y;
            String mulvalue=String.valueOf(k);
            Toast.makeText(this, mulvalue, Toast.LENGTH_LONG).show();
        }
        else
        {
            int g=x/y;
            String divvalue=String.valueOf(g);
            Toast.makeText(this, divvalue, Toast.LENGTH_LONG).show();
        }
    }
}   
  • 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-31T20:14:52+00:00Added an answer on May 31, 2026 at 8:14 pm

    Bob Kaufman’s comment is correct. You are falling through to your else statement by virtue of the comparisons you are making. To compare strings in Java you should use the equals(Object o) or equalsIgnoreCase methods, not == unless you want to determine if the Strings being compared are the same object.

    On top of that, it’s not really clear what is being returned by getItemAtPosition since we can’t see what kind of SpinnerAdapter you are using. So, it may not even be appropriate to do the String comparisons in the first place.

    Like, Bob, I suspect you are getting 0 because of integer division. If you put, say, 100 in txt1 and, say, 40, in txt2, I would guess your Toast would read 2.

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

Sidebar

Related Questions

I develop application in Java and Spring AOP. Anything is good, but I've created
I develop an application on PyQt, I like the signal-slot model, but is there
I have to develop the application based on a spinner. I have taken the
I want to develop application for Android tablet . But I am unable to
I want to develop an application for blind using J2ME or Android. but i
i develop application for Blackberry. In Storm 1 (4.7) and Storm 2 (5.0) i
We develop Win32 application that access to SQL 2005 database through Linq to SQL.
I have to develop an application which parses a log file and sends specific
As you develop an application database changes inevitably pop up. The trick I find
I have to develop an application using C#.net that has to be run once

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.