0

I'm facing a strange problem with my code. This is my layout:

<RelativeLayout
        android:id="@+id/container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:background="@android:color/transparent"
            android:digits="0123456789,."
            android:gravity="center"
            android:imeOptions="actionDone"
            android:inputType="numberDecimal"
            android:selectAllOnFocus="true"
            android:textSize="@dimen/sp15" />

</RelativeLayout>

And this is code for opening keyboard:

container.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(editText.hasFocus()) {
                editText.clearFocus();
            }
            editText.requestFocus();
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(currentStake, InputMethodManager.SHOW_IMPLICIT);
        }
    });

Now on most devices, when i tap on container, text inside edittext is all selected, numeric keyboard appear and i can type numbers (for example 15,20, etc). On Huawei devices the behavior is different. In fact when user tap on container text inside edittext is all selected, numeric keyboard appear, but every time i type a digit, text continue keep selected, so i'm not able to type numbers > 9. For example if i type 20, when i press 2, on edittext 2 appear (but selected), and when i press 0, this replace 2 so i have a 0 inside edittext and not 20. I'm going crazy to find a solution, how can i do?

giozh
  • 9,868
  • 30
  • 102
  • 183
  • 1
    Maybe try to select all in the onclicklistener and remove the line android:selectAllOnFocus="true" from xml – Chol May 11 '17 at 10:11
  • is this maybe related to autocorrection? Have you tried to switch to another keyboard in your device settings? – Opiatefuchs May 11 '17 at 10:31
  • Maybe you should change the attribute `android:selectAllOnFocus="true"` to false, it could be a wrong implementation on Huawei side... – Opiatefuchs May 11 '17 at 10:34
  • Answer of Chol works, thanks. I've try the other solutions but no one works. – giozh May 11 '17 at 12:54

0 Answers0