title: how to make a backspace button that removes the last character of a stringbuilder inside a for loop
body: <p>I am making an Android app that receives different level of voltages from arduino to the android via bluetooth and translate it into letters. My app can already translate it into letters, and my problem now is I dont know how to delete the last letter in the stringbuilder which is inside a for loop.. I have this button called backspace and i want it to work with the same function like in a computers's backspace wherein pressing it will delete the last letter.. I hope someone can help me, im still new to this.</p>
  
  <p>note: these codes are from the Main Activity;
  sbletter is a stringbuffer that appends letters</p>
  
  <pre><code>boolean test = false;
  char[] charArray = sbletter.toString().toCharArray();
  char currentletter =' ';
  char prevletter =' '; 
  
  StringBuilder strBuild1 = new StringBuilder();
  
      for(int i = 0; i &lt; charArray.length; i++) {
          currentletter = charArray[i];
              if(curletter != prevletter) {
                  strBuild1.append(charArray[i]);
                      if(test){
                         strBuild1.deleteCharAt(strBuild1.length()-1); 
                      }
                  test = false;
              }
                  prevletter = currentletter;
          }
  
  SecondActivity.textView1.setText(strBuild1.toString());
  
  SecondActivity.backspace.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View view) {
  
                  test = true;
  
              }
  
          });
  </code></pre>