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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:07:54+00:00 2026-05-30T14:07:54+00:00

I’m trying to design a simple calculator for use as a scoreboard for a

  • 0

I’m trying to design a simple calculator for use as a scoreboard for a game or two. Ultimately, I want to be able to select the number of players, have that many score-trackers appear on screen, be able to use a the touch calculator to add or subtract (or divide or multiply) I got it to work for the most part.

Currently, it takes the text inputted in the calculator display, adds/subtracts/whatever that to the player score that I choose.

The problem is trying to get the numerical keys to show up in the calculator display part. For instance, I want to be able to hit “1” then “0” and have “10” appear in the calculator. It should have been easy, seeing as I am able to input text MANUALLY (using the android default keyboard), but the closest I can get is for only 1 number to show up at a time…

Long story short, I am trying to get a touch-pad type calculator’s numerical buttons to work and display. Below is my main project code. If you need my layout code, I can post that as well (for references to IDs).

I know it’s probably a simple solution, but every tutorial I find is either overly complicated or does not work… ANY help is greatly appreciated!

package com.MCalculator8.test;

import com.MCalculator8.test.R;

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

public class MCalculator8Activity extends Activity {
    private EditText player1name;
    private EditText player2name;
    private EditText player3name;
    private EditText player4name;
    private EditText player5name;
    private EditText player6name;
    private EditText player7name;

    private EditText player1score;
    private EditText player2score;
    private EditText player3score;
    private EditText player4score;
    private EditText player5score;
    private EditText player6score;
    private EditText player7score;

    private EditText input;

    private TextView operator;
    private MCalculator8Activity mContext;

    // Called when the activity is first created. 
    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mContext = this;

            setContentView(R.layout.main);

            player1name = (EditText) findViewById(R.id.player1name);
            player2name = (EditText) findViewById(R.id.player2name);
            player3name = (EditText) findViewById(R.id.player3name);
            player4name = (EditText) findViewById(R.id.player4name);
            player5name = (EditText) findViewById(R.id.player5name);
            player6name = (EditText) findViewById(R.id.player6name);
            player7name = (EditText) findViewById(R.id.player7name);

            input = (EditText) findViewById(R.id.input);

            player1score = (EditText) findViewById(R.id.player1score);
            player2score = (EditText) findViewById(R.id.player2score);
            player3score = (EditText) findViewById(R.id.player3score);
            player4score = (EditText) findViewById(R.id.player4score);
            player5score = (EditText) findViewById(R.id.player5score);
            player6score = (EditText) findViewById(R.id.player6score);
            player7score = (EditText) findViewById(R.id.player7score);

            operator = (TextView) findViewById(R.id.operator);

            // We create an OnClick Event in each button.

            Button plusButton = (Button) findViewById(R.id.add);
            Button minusButton = (Button) findViewById(R.id.subtract);
            Button multiplyButton = (Button) findViewById(R.id.multiply);
            Button player1equals = (Button) findViewById(R.id.player1equals);
            Button player2equals = (Button) findViewById(R.id.player2equals);
            Button player3equals = (Button) findViewById(R.id.player3equals);
            Button player4equals = (Button) findViewById(R.id.player4equals);
            Button player5equals = (Button) findViewById(R.id.player5equals);
            Button player6equals = (Button) findViewById(R.id.player6equals);
            Button player7equals = (Button) findViewById(R.id.player7equals);

            plusButton.setOnClickListener(new OnClickListener() {

                    public void onClick(View arg0) {

                            operator.setText("+");

                    }

            });

            minusButton.setOnClickListener(new OnClickListener() {

                    public void onClick(View arg0) {

                            operator.setText("-");

                    }

            });

            multiplyButton.setOnClickListener(new OnClickListener() {

                    public void onClick(View arg0) {

                            operator.setText("x");

                    }

            });


            player1equals.setOnClickListener(new OnClickListener() {

                    private AlertDialog show;

                    public void onClick(View arg0) {

                            if ((input.getText().length() == 0)
                                            || (input.getText().toString() == " ")) {
                                         //   || (input2.getText().length() == 0)
                                         //   || (input2.getText().toString() == " ")) {

                                    show = new AlertDialog.Builder(mContext).setTitle("Error")
                                                    .setMessage("Some inputs are empty")
                                                    .setPositiveButton("OK", null).show();

                            } else if (operator.getText().equals("")) {

                                    show = new AlertDialog.Builder(mContext).setTitle("Error")
                                                    .setMessage("Operator is null").setPositiveButton(
                                                                    "OK", null).show();

                            } else if (operator.getText().equals("+")) {

                                    double result = new Double(input.getText().toString())
                                                    + new Double(player1score.getText().toString());

                                    player1score.setText(Double.toString(result));

                            } else if (operator.getText().equals("-")) {

                                    double result = new Double(player1score.getText().toString())
                                                    - new Double(input.getText().toString());

                                    player1score.setText(Double.toString(result));

                            } else if (operator.getText().equals("x")) {

                                    double result = new Double(input.getText().toString())
                                                    * new Double(player1score.getText().toString());


                                    player1score.setText(Double.toString(result));

                            }

                    }

            });
  • 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-30T14:07:55+00:00Added an answer on May 30, 2026 at 2:07 pm

    How is this example?

    Here is the Main Class called “CalculatorExample.java”

    package com.calculatorExample;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class CalculatorExample extends Activity implements android.view.View.OnClickListener{
        Button add, subtract, multiply, divide;
        TextView firstInput, secondInput, output;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            // Reference TextViews and Buttons
            firstInput = (TextView) findViewById(R.id.firstIput);
            secondInput = (TextView) findViewById(R.id.secondInput);
            output = (TextView) findViewById(R.id.output);
            add = (Button) findViewById(R.id.add);
            subtract = (Button) findViewById(R.id.subtract);
            multiply = (Button) findViewById(R.id.multiply);
            divide = (Button) findViewById(R.id.divide);
    
            // Set listeners for when buttons are pressed
            add.setOnClickListener(this);
            subtract.setOnClickListener(this);
            multiply.setOnClickListener(this);
            divide.setOnClickListener(this);
    
        }
    
        /**
         * Switch statement to decide which button was pressed
         */
        public void onClick(View arg0) {
            // Get values from top two TextViews
            double firstInputValue = Double.parseDouble(firstInput.getText().toString());
            double secondInputValue = Double.parseDouble(secondInput.getText().toString());
            // Initialise output
            double outputValue = 0;
    
            // Perform relevant operations
            switch(arg0.getId()){
            case R.id.add:
                outputValue = firstInputValue + secondInputValue;
                break;
            case R.id.subtract:
                outputValue = firstInputValue - secondInputValue;
                break;
            case R.id.multiply:
                outputValue = firstInputValue * secondInputValue;
                break;
            case R.id.divide:
                outputValue = firstInputValue / secondInputValue;
                break;
            }
            // Add result to Running total stored in output TextView
            outputValue += Double.parseDouble(output.getText().toString());
            output.setText("" + outputValue);
    
        }
    }
    

    And here is the XML file (“main.xml”)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <LinearLayout 
            android:weightSum="100"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
        >
            <EditText 
                android:layout_weight="50"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/firstIput">
            </EditText>
            <EditText 
                android:layout_weight="50"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:id="@+id/secondInput">
            </EditText>
        </LinearLayout>
        <LinearLayout 
            android:weightSum="100"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
        >
            <Button 
                android:layout_weight="50"
                android:text="+" 
                android:id="@+id/add" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
            </Button>
            <Button 
                android:layout_weight="50"
                android:text="-" 
                android:id="@+id/subtract" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
            </Button>
        </LinearLayout>
        <LinearLayout 
            android:weightSum="100"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
        >
            <Button 
                android:layout_weight="50"
                android:text="X" 
                android:id="@+id/multiply" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
            </Button>
            <Button 
                android:layout_weight="50"
                android:text="/" 
                android:id="@+id/divide"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
            </Button>
        </LinearLayout>
        <EditText 
            android:text="0.0"
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:id="@+id/output">
        </EditText>
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.