Reputation: 1677
I created an Application to dial particular contact number. It has one EditText and ten buttons for the digits from 0 to 9 and a BACK button. I want to erase single digit from EditText on each click event of BACK button. Is there any way to do so ?
Upvotes: 0
Views: 972
Reputation: 2707
Namaskar modiji, try
myButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
String text = et.getText().toString();
if(!TextUtils.isEmpty(text)){
String newText = text.substring(1, text.length()); //delete from left
//or
String newText1 = text.substring(0, text.length() - 1); //delete from right
et.setText(newText);
et.setSelection(newText.length());
//or
et.setText(newText1);
et.setSelection(newText1.length());
}
}
}
Upvotes: 2