I am making an android app in java.. And basicaly i have a problem.. I have a button which is removing the last char in a string.. And this button will be used alot and if the user is pressing the button while the string is empty the application gets an error message and closes.. And i want to prevent this somehow..
This is current code for the onClickListener..
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
value = value.substring(0, value.length() - 1);
numbersArea.setText(value);
}
Any idea how i would do this?? Since im out of ideas after trying all yesterday night.
Make your listener like this:
Basically, what it does is verify if the string is empty and different of null, if its not, it enters in the
ifstatement.Please, let me know if you have more doubts.
Thanks.