title: Problems with making an Android calculator app
body: <p>I'm new to Android and I am trying to make a simple calculator app that takes two operands and either adds, subtracts, multiplies, or divides them. The problem I am having is when I hit equals after entering in the correct format, it gives me a result of 0 or 1. I think it is comparing objects together and returning 0 if it isn't the same and 1 if it is the same, but I have no idea which objects it is comparing. What am I doing wrong?</p>
  
  <p>This is my MainActivity.java file:</p>
  
  <pre><code>package com.example.simplecalculator;
  
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.*;
  import android.view.View;
  import android.view.View.OnClickListener;
  
  public class MainActivity extends ActionBarActivity implements OnClickListener
  {
  
      private EditText output;
      private Button num_0;
      private Button num_1;
      private Button num_2;
      private Button num_3;
      private Button num_4;
      private Button num_5;
      private Button num_6;
      private Button num_7;
      private Button num_8;
      private Button num_9;
      private Button op_plus;
      private Button op_minus;
      private Button op_multiply;
      private Button op_divide;
      private Button equals;
      private Button clear;
      private long operand1;
      private long operand2;
      private long result;
      private String operator;
      private StringBuilder set1;
      private StringBuilder set2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          operator = "";
          operand1 = -1;
          operand2 = -1;
          set1 = new StringBuilder();
          set2 = new StringBuilder();
          output = (EditText)findViewById(R.id.output);
          num_0 = (Button)findViewById(R.id.num_0);
          num_1 = (Button)findViewById(R.id.num_1);
          num_2 = (Button)findViewById(R.id.num_2);
          num_3 = (Button)findViewById(R.id.num_3);
          num_4 = (Button)findViewById(R.id.num_4);
          num_5 = (Button)findViewById(R.id.num_5);
          num_6 = (Button)findViewById(R.id.num_6);
          num_7 = (Button)findViewById(R.id.num_7);
          num_8 = (Button)findViewById(R.id.num_8);
          num_9 = (Button)findViewById(R.id.num_9);
          op_plus = (Button)findViewById(R.id.op_plus);
          op_minus = (Button)findViewById(R.id.op_minus);
          op_multiply = (Button)findViewById(R.id.op_multiply);
          op_divide = (Button)findViewById(R.id.op_divide);
          equals = (Button)findViewById(R.id.equals);
          clear = (Button)findViewById(R.id.clear);
  
          num_0.setOnClickListener(this);
          num_1.setOnClickListener(this);
          num_2.setOnClickListener(this);
          num_3.setOnClickListener(this);
          num_4.setOnClickListener(this);
          num_5.setOnClickListener(this);
          num_6.setOnClickListener(this);
          num_7.setOnClickListener(this);
          num_8.setOnClickListener(this);
          num_9.setOnClickListener(this);
          op_plus.setOnClickListener(this);
          op_minus.setOnClickListener(this);
          op_multiply.setOnClickListener(this);
          op_divide.setOnClickListener(this);
          equals.setOnClickListener(this);
          clear.setOnClickListener(this);     
      }
  
      @Override
      public void onClick(View v)
      {
          switch(v.getId())
          {
              case R.id.num_0:
                  output.append(num_0.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_0.getText().toString());
                  }
                  else
                  {
                      set2.append(num_0.getText().toString());
                  }
                  break;
  
              case R.id.num_1:
                  output.append(num_1.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_1.getText().toString());
                  }
                  else
                  {
                      set2.append(num_1.getText().toString());
                      operand2 = Long.parseLong(set2.toString());
                  }
                  break;
  
              case R.id.num_2:
                  output.append(num_2.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_2.getText().toString());
                  }
                  else
                  {
                      set2.append(num_2.getText().toString());
                  }
                  break;
  
              case R.id.num_3:
                  output.append(num_3.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_3.getText().toString());
                  }
                  else
                  {
                      set2.append(num_3.getText().toString());
                  }
                  break;
  
              case R.id.num_4:
                  output.append(num_4.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_4.getText().toString());
                  }
                  else
                  {
                      set2.append(num_4.getText().toString());
                  }
                  break;
  
              case R.id.num_5:
                  output.append(num_5.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_5.getText().toString());
                  }
                  else
                  {
                      set2.append(num_5.getText().toString());
                  }
                  break;
  
              case R.id.num_6:
                  output.append(num_6.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_6.getText().toString());
                  }
                  else
                  {
                      set2.append(num_6.getText().toString());
                  }
                  break;
  
              case R.id.num_7:
                  output.append(num_7.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_7.getText().toString());
                  }
                  else
                  {
                      set2.append(num_7.getText().toString());
                  }
                  break;
  
              case R.id.num_8:
                  output.append(num_8.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_8.getText().toString());
                  }
                  else
                  {
                      set2.append(num_8.getText().toString());
                  }
                  break;
  
              case R.id.num_9:
                  output.append(num_9.getText());
                  if(operand1 == -1)
                  {
                      set1.append(num_9.getText().toString());
                  }
                  else
                  {
                      set2.append(num_9.getText().toString());
                  }
                  break;
  
              case R.id.op_plus:
                  if(operand1 == -1)
                  {
                      operator = "+";
                      operand1 = Long.parseLong(set1.toString());
                      output.append(operator);
                  }
                  break;
  
              case R.id.op_minus:
                  if(operand1 == -1)
                  {
                      operator = "-";
                      operand1 = Long.parseLong(set1.toString());
                      output.append(operator);
                  }
                  break;
  
              case R.id.op_multiply:
                  if(operand1 == -1)
                  {
                      operator = "*";
                      operand1 = Long.parseLong(set1.toString());
                      output.append(operator);
                  }
                  break;
  
              case R.id.op_divide:
                  if(operand1 == -1)
                  {
                      operator = "/";
                      operand1 = Long.parseLong(set1.toString());
                      output.append(operator);
                  }
                  break;
  
              case R.id.equals:
                  operand2 = Long.parseLong(set2.toString());
                  switch(operator)
                  {
                      case "+":
                          result = operand1 + operand2;
  
                      case "-":
                          result = operand1 - operand2;
  
                      case "*":
                          result = operand1 * operand2;
  
                      case "/":
                          result = operand1 / operand2;
                  }
                  output.setText(""+result);
                  operator = null;
                  operand1 = -1;
                  operand2 = -1;
                  set1.setLength(0);
                  set2.setLength(0);
                  break;
  
              case R.id.clear:
                  output.setText("");
                  operator = null;
                  operand1 = -1;
                  operand2 = -1;
                  set1.setLength(0);
                  set2.setLength(0);
                  break;
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) 
      {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) 
      {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) 
          {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>And this is my activity_main.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context="com.example.simplecalculator.MainActivity" &gt;
  
      &lt;LinearLayout 
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"
          android:layout_weight="1" &gt;
  
          &lt;EditText
              android:id="@+id/output"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:text="@string/start_value"&gt;  
          &lt;/EditText&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout 
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"
          android:layout_weight="1" &gt;
  
          &lt;Button
              android:id="@+id/num_7"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_7"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/num_8"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_8"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/num_9"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_9"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/op_plus"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/op_plus"&gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout 
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"
          android:layout_weight="1" &gt;
  
          &lt;Button
              android:id="@+id/num_4"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_4"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/num_5"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_5"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/num_6"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_6"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/op_minus"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/op_minus"&gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout 
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"
          android:layout_weight="1" &gt;
  
          &lt;Button
              android:id="@+id/num_1"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_1"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/num_2"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_2"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/num_3"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_3"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/op_multiply"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/op_multiply"&gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout 
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"
          android:layout_weight="1" &gt;
  
          &lt;Button
              android:id="@+id/num_0"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/num_0"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/clear"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/clear"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/equals"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/equals"&gt;
          &lt;/Button&gt;
  
          &lt;Button
              android:id="@+id/op_divide"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:text="@string/op_divide"&gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Edit: Here is my strings.xml file as well</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  
      &lt;string name="app_name"&gt;SimpleCalculator&lt;/string&gt;
      &lt;string name="action_settings"&gt;Settings&lt;/string&gt;
      &lt;string name="start_value"&gt;&lt;/string&gt;
      &lt;string name="num_0"&gt;0&lt;/string&gt;
      &lt;string name="num_1"&gt;1&lt;/string&gt;
      &lt;string name="num_2"&gt;2&lt;/string&gt;
      &lt;string name="num_3"&gt;3&lt;/string&gt;
      &lt;string name="num_4"&gt;4&lt;/string&gt;
      &lt;string name="num_5"&gt;5&lt;/string&gt;
      &lt;string name="num_6"&gt;6&lt;/string&gt;
      &lt;string name="num_7"&gt;7&lt;/string&gt;
      &lt;string name="num_8"&gt;8&lt;/string&gt;
      &lt;string name="num_9"&gt;9&lt;/string&gt;
      &lt;string name="op_plus"&gt;+&lt;/string&gt;
      &lt;string name="op_minus"&gt;-&lt;/string&gt;
      &lt;string name="op_multiply"&gt;*&lt;/string&gt;
      &lt;string name="op_divide"&gt;/&lt;/string&gt;
      &lt;string name="clear"&gt;C&lt;/string&gt;
      &lt;string name="equals"&gt;=&lt;/string&gt;
  
  &lt;/resources&gt;
  </code></pre>