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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:32:22+00:00 2026-06-14T02:32:22+00:00

I am trying to sort a calculator app out in android. I have the

  • 0

I am trying to sort a calculator app out in android. I have the layout set out fine and now I just need to do the code that will calculate. The app needs to show the number when it is pressed, then if say the + button is pressed it will store the first number, clear it off the screen, get a second number and then add them together. When the equal button is pressed it needs to show the results.

So far I have

public class Calculator extends Activity {

    public EditText display;  
    TextView screen;
    int a, result;
    int c;
    Button b1;
    int sum1, sum2;
    String r;

    public int getSum1(int sum1) {
        return sum1;
    }

    public int getSum2(int sum2) {
        return sum2;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);  

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void buttonEventHandler(View v) {
        screen=(EditText)findViewById(R.id.screen);
        b1=(Button)findViewById(R.id.button1);
        switch(v.getId()) {

        case R.id.button1 :
            screen.setText(screen.getText() + "1");
            c = +1;
            break;

        case R.id.button2 : 
            screen.setText(screen.getText() + "2");
            c = +2;
            break;

        case R.id.button3 : 
            screen.setText(screen.getText() + "3");
            c = +3;
            break;

        case R.id.button4 : 
            screen.setText(screen.getText() + "4");
            c = +4;
            break;

        case R.id.button5 : 
            screen.setText(screen.getText() + "5");
            c = +5;
            break;

        case R.id.button6 : 
            screen.setText(screen.getText() + "6");
            c = +6;
            break;

        case R.id.button7 : 
            screen.setText(screen.getText() + "7");
            c = +7;
            break;

        case R.id.button8 : 
            screen.setText(screen.getText() + "8");
            c = +8;
            break;

        case R.id.button9 : 
            screen.setText(screen.getText() + "9");
            c = +9;
            break;

        case R.id.button0 : 
            screen.setText(screen.getText() + "0");
            c = +0;
            break;

        case R.id.buttonC :
            screen.setText(screen.getText() + "");
            c = 0;
            break;

        case R.id.buttonPlus :          


        case R.id.buttonEquals :



        }


    }
}

How to do calculations?

  • 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-14T02:32:24+00:00Added an answer on June 14, 2026 at 2:32 am

    Set your sum1 to zero in onCreate. When the user taps +, do:

    1. Add c to sum1
    2. Display sum1
    3. Reset c to zero so a new number can be typed

    When the user taps =, do:

    1. Add c to sum1
    2. Display sum1
    3. Reset c and sum1 to zero

    This allows you to tap 4 + 5 + 6 = and see 15, for example.

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

Sidebar

Related Questions

So I'm trying to make a Python app that's sort of like a set
I've been trying to sort this out for a while now, I have checked
I'm trying to code part of a program that allows users to set up
Been trying to sort this one out for a while. I'd really appreciate any
I'm trying to sort by the state of an Organization's main address. I have
I'm stuck on a problem I'm trying to sort out with calculating multiple arrays.
I'm trying to create a MySQL statement that will sort by a value calculated
I recently encountered some problems while trying to sort a set of objects. The
I have 16 threads that calculate the hash of a key. I'm trying to
Problem description : I'm trying to define a pl/python aggregator that receives a set

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.