i'm building a simple binary decimal converter and i want the binary strings to be formatted in groups of 4 bits as the user inputs them.
Watching other similar questions led me to manipulate the editable in method "afterTextChanged" but when i run the app and input the 4° digit the app freezes and the RAM monitor starts to go crazy.
Also, my edittext "binary" is set to "numberDecimal". I tried to change that temporarily using something i found Here, but i can't seem to get it working.
Here's the code: (binary is my EditText)
binary.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if(binary.isFocused()){
temp = binary.getText().toString().replaceAll("\\s+","");
if(temp.length()%4==0){
InputFilter[] filters = editable.getFilters(); // save filters
editable.setFilters(new InputFilter[] {}); // clear filters
editable.insert(editable.length()-1," "); // edit text
editable.setFilters(filters);
}
Thank you in advance :D