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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:40:19+00:00 2026-06-15T21:40:19+00:00

hi to all i have android application which is calculator that perform only one

  • 0

hi to all i have android application which is calculator that perform only one operation (addition) the result is always 3.0 whatever the two numbers are
what is the solution???
here is the code

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class claculator extends Activity {
    /** Called when the activity is first created. */

    EditText nu1,nu2;
    Button add;
    TextView txtv;
    double x,y,z;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        nu1=(EditText)findViewById(R.id.n1);
        nu2=(EditText)findViewById(R.id.n2);
        add=(Button)findViewById(R.id.btn);
        txtv=(TextView)findViewById(R.id.tv);

         x= Double.parseDouble(nu1.getText().toString());
       y= Double.parseDouble(nu2.getText().toString());

       add.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            z=x+y;
            txtv.setText(String.valueOf(z));
        }
    });

    }
} 
  • 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-15T21:40:21+00:00Added an answer on June 15, 2026 at 9:40 pm

    You must fetch the EditText values inside onClick():

    add.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            x= Double.parseDouble(nu1.getText().toString());
            y= Double.parseDouble(nu2.getText().toString());
    
            z=x+y;
            txtv.setText(String.valueOf(z));
        }
    });
    

    When you try to get these values in onCreate() the user hasn’t had a chance to alter them yet, you will get their default values. You must fetch these values when the user clicks the Button.

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

Sidebar

Related Questions

I have a Android Application which is basically uses WebView for all interaction.. How
I have a Android application which i use almost all the sensors and some
I have an Android application that generates some HTML which is rendered locally, in
I have used share inbuilt dialog of android. Which fetch all application which is
We have developed one android application which will send the request and receive the
I have one Application in which i have to show All wall Post of
In my Android application I have to use common string value for all activities.
I have about 8 entities that all have a one to one relationship with
In my android application , i have three pages A,B,C.All the three pages have
I am creating an Android application which will have some embedded music inside of

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.