title: What is the best way to delete the last digit in a calculator app
body: <pre><code>package com.gamesup.braingame;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  
  public class Easy extends Activity {
  
  EditText display;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.easy);
      display = (EditText)findViewById(R.id.displayText);
      display.setText("?");
  
  }
  
  static boolean isEmpty = true;
  
  public void num_Clicked(View v){
      Button btn = (Button) findViewById(v.getId());
      //getting the button object and using a view to get the id of the buttons
  
      if(isEmpty){
          display.setText(btn.getText());
          isEmpty = false;
      }
      else{
          display.append(btn.getText().toString()); 
      }
  
      if (v.getId()== R.id.del_button){
          String s = display.getText().toString();
          s = s.substring(0, s.length() - 1);
          display.setText(s);
  
      }
  
  
  }
  
  
  
  }
  </code></pre>
  
  <p>This is my code for the digits to be displayed on a calculator android app. <strong>What would i have to use to delete the last digit displayed?</strong> Also would i do this inside the <code>num_Clicked</code> function, like this:</p>
  
  <pre><code>if (v.getId()== R.id.del_button) {
  
  }
  </code></pre>
  
  <p>This is my xml code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
       &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" &gt;
   &lt;TableLayout
      android:id="@+id/tableLayout1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true" &gt;
  
  &lt;TableRow
          android:id="@+id/tableRow1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
   &lt;Button
              android:id="@+id/number1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_1_label" /&gt;
  
  &lt;Button
              android:id="@+id/number2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_2_label" /&gt;
  
   &lt;Button
              android:id="@+id/number3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_3_label" /&gt;
  
  &lt;/TableRow&gt;
  
  &lt;TableRow
          android:id="@+id/tableRow2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
  &lt;Button
              android:id="@+id/number4"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_4_label" /&gt;
  
  &lt;Button
              android:id="@+id/number5"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_5_label" /&gt;
  
  &lt;Button
              android:id="@+id/number6"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_6_label" /&gt;
  
  &lt;/TableRow&gt;
  
  &lt;TableRow
          android:id="@+id/tableRow3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
  
  &lt;Button
              android:id="@+id/number7"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_7_label" /&gt;
  
  
  &lt;Button
              android:id="@+id/number8"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_8_label" /&gt;
  
  
   &lt;Button
              android:id="@+id/number9"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_9_label" /&gt;
  
  
  &lt;/TableRow&gt;
  
  
   &lt;TableRow
          android:id="@+id/tableRow4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
  &lt;Button
              android:id="@+id/del_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/delete_label" /&gt;
  
  &lt;Button
              android:id="@+id/number0"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/number_0_label" /&gt;
  
  
  &lt;Button
              android:id="@+id/hash_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/hash_label" /&gt;
  
  &lt;Button
              android:id="@+id/minus_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:onClick="num_Clicked"
              android:text="@string/minus_label" /&gt;
  
  &lt;/TableRow&gt;
  
  
  &lt;/TableLayout&gt;
  
  &lt;EditText
      android:id="@+id/displayText"
      android:layout_width="wrap_content"
      android:layout_height="50dp"
      android:layout_above="@+id/tableLayout1"
      android:layout_alignLeft="@+id/tableLayout1"
      android:layout_alignRight="@+id/tableLayout1"
      android:ems="10"
      android:inputType="number" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>