Gboard键盘:数字inputType不适用于ListView中的EditText

时间:2017-07-14 07:12:37

标签: android android-layout android-xml android-keypad gboard

我使用默认的Android Gboard keyboard。但是当我在inputType="number"上使用EditText时出现问题。显示的键盘但类型值未显示在EditText中,也未在TextWatcher中获取任何类型值。

EditText元素中的ListView如下所示:

<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" />

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" />

这是我的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) {

        }
    });

1 个答案:

答案 0 :(得分:0)

TextWatcher的问题是它与ListView的效果并不好。您必须像这样定义自己的自定义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());
    }      
}

并在getView()内执行此操作:

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

最后在viewHolder初始化您的EditText并向其添加自定义TextWatcher