views:

69

answers:

1

Hi all

Im trying to strip all non standard letter characters from an edittext textbox on an android app im making. I am successfully creating a listener, obtaining the value and removing bad chrs via a regex. however, the .setText line below causes the app to crash. Anyone got any ideas how to get around this and dynamically mask certain chrs?

filenameTextBox.addTextChangedListener(new TextWatcher() {

  public void onTextChanged(CharSequence s, int start, int before, int count) {

   FILENAME=s.toString();
   FILENAME = FILENAME.replaceAll("[^a-zA-Z]", "");
   filenameTextBox.setText(FILENAME);

} }

A: 

Aren't you creating an infinite loop? You can log each time the handler is called and see how many times it's called.

GôTô
Goto; you genius! Thanks, that was an important lesson in remembering to use debug.
arkid77
however, how do i resolve this? I dont know what method I can use to force an update of the text if i find i want to correct it as its typed. The problem also occurs on afterTextChanged method.
arkid77
Use a class boolean variable to check if the method is already running. Check if it is true at the begining of the method: if not, set it to true and do the job. Don't forget to set it to false at the end.
GôTô