A
A
Alex2015-08-04 09:04:20
Android
Alex, 2015-08-04 09:04:20

How to bypass incorrect work of EditText.setSelection() on Asus devices?

Good afternoon.
I have two InputFilters attached to an EditText: a standard AllCaps() filter to convert letters to uppercase, and a self-written one to allow input of alphabetic characters. Everything works fine, but not on Asus devices (Zenfone 4 and 5 on Intel).
In addition to filters, a TextWatcher is attached to the EditText, transliterating the entered Latin characters into Russian (code below).
The problem on Asus devices is the following: the device does not allow you to enter more than one letter. It looks like the problem is setting the cursor via EditText.setSelection(). If you do not use this method of specifying the cursor location, then any desired number of letters is entered into the input field (with the wrong cursor, of course, which "mixes" the text).
The code:

etCardholder.setFilters(new InputFilter[]{new InputFilter.AllCaps(), new NameInputeFilter(false)});

twTransliterator = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        etCardholder.removeTextChangedListener(twTransliterator);
        etCardholder.setText(StringTools.transliterateCharacterRuToEn(s.toString())); // Делаем преобразования и устанавливаем результат в EditText
        etCardholder.addTextChangedListener(twTransliterator);
    }

    @Override
    public void afterTextChanged(Editable s) {
        etCardholder.setSelection(etCardholder.getText().length()); // Устанавливаем курсор в конец
    }
};

What could be the problem with the devices of this company and how can I get around it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question