简体   繁体   English

Gboard键盘:数值inputType在ListView中的EditText上不起作用

[英]Gboard Keyboard: Numeric inputType not working on EditText in ListView

I am using default Android Gboard keyboard . 我正在使用默认的Android Gboard键盘 But there is an issue when I am using inputType="number" on the EditText . 但是当我在EditText上使用inputType="number"时出现问题。 The keyboard shown but type values not display in EditText , also not getting any type value in TextWatcher. 显示的键盘但类型值未在EditText显示,在TextWatcher中也未获得任何类型值。

The EditText in the ListView element looks like the following: ListView元素中的EditText如下所示:

<EditText
    android:id="@+id/editTextChecked"
    android:layout_width="150dp"
    android:layout_height="60dp"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_gravity="center"
    android:gravity="center"      
    android:inputType="number"
    android:textColor="#000000" />

The ListView is defined as: ListView定义为:

<ListView
    android:id="@+id/listViewDialog"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottom"
    android:layout_below="@+id/editTextSearch"
    android:background="@android:color/white"
    android:divider="@android:color/darker_gray"
    android:dividerHeight="1dp" />

This is my TextWather Code :- 这是我的TextWather代码:-

 holder.etCheck.addTextChangedListener(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) {
            Log.e("text",""+s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

The thing with TextWatcher is that it doesn't work so well with ListView s. TextWatcher在于,它不适用于ListView You have to define your own custom TextWatcher like this: 您必须像这样定义自己的自定义TextWatcher

private class MyCustomEditTextListener implements TextWatcher {
    private int position;

    public void updatePosition(int position) {
        this.position = position;
    }

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        // do your operations here.
    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    }

    @Override
    public void afterTextChanged(Editable editable) {
        Logger.e(TAG, "After" + editable.toString());
    }      
}

and inside getView() do this: getView()内部执行此操作:

((Viewholder) holder).myCustomEditTextListener.updatePosition(position);

Finally inside your viewHolder initialise your EditText and add the custom TextWatcher to it. 最后,在viewHolder内部初始化EditText并将自定义TextWatcher添加到其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM