EditText with assigned InputFilter / decimal separator hidden in landscape mode

I am having a very strange problem with EditText with assigned InputFilter in the application I am writing. The idea is to have an EditText that accepts only decimal numbers as input with a maximum of two decimal places and a decimal separator according to the user's locale settings. Here are the relevant code snippets

Editing text in layout

<EditText android:id="@+id/value" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="01234567890,." android:inputType="number|numberDecimal" android:nextFocusForward="@+id/category" > 

Implementing InputFilter

 public class MoneyFilter implements InputFilter { private String testRegex; public MoneyFilter(String decimalSep) { testRegex = "^\\d+\\" + decimalSep + "?\\d{0,2}$"; } @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { String s = source.toString(); String d = dest.toString(); String r = d.substring(0, dstart) + s.substring(start, end) + d.substring(dend); if (r.matches(testRegex)) { return null; } else { return ""; } } } 

And the purpose of the InputFilter for my EditText in related activity

 getValue().setFilters( new InputFilter[] { new MoneyFilter(decimalSeperator) }); 

decimalSeparator is read from the locale settings, and getValue () just calls findViewById (...) with some casting to the correct type.

In general, my implementation seems to work exactly as intended, but shows one weird behavior. When the decimal separator is already entered and the screen orientation changes to landscape mode, it is hidden, all numbers remain visible. As soon as the orientation is changed back to portrait mode, it will be shown again. I can even enter the decimal separator in landscape mode, although it will not be shown in EditText until the device returns to portrait mode.

I could reproduce the behavior on my Android 4.3 device and in an emulator with API levels 18 and 10. Removing android: numbers and / or android: inputType from EditText will not change this behavior, other EditText widgets without InputFilter behave completely normal, so I I think that this is somehow connected with this filter.

A few hours of research did not bring anything useful, so some of them are welcome :) If you need more information or code, just let me know.

Yours faithfully,

Hans

+1
android android-layout android-edittext
source share
1 answer

It looks like you are faced with a known problem ( https://code.google.com/p/android/issues/detail?id=2626 ) that Google has not fixed since ancient times.

In landscape mode, the IME by default uses a full-screen or technically ExtractEditText, which does not respect locale settings.

You can solve this problem by disabling ExtractEditText as follows: android: imeOptions = "flagNoExtractUi"

+3
source share

All Articles