当在ListView或RecyclerView中集中EditText时,键盘显示但滚动不起作用

时间:2015-07-07 07:42:02

标签: android listview scroll android-edittext android-recyclerview

当我触摸ListView或RecyclerView内的EditText时,显示软键盘。然后我点击键盘上的下一个按钮,焦点变为下一个EditText。在最后一个可见的EditText之后,焦点变为下一个EditText但ListView或RecyclerView没有在里面滚动,所有屏幕都在状态栏下每个键盘下一个Button点击。

以下用于此屏幕的xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include
            android:id="@+id/MainToolbar"
            layout="@layout/toolbar" />
        <include
            android:id="@+id/llHeaderItem"
            layout="@layout/TaskShelfShareHeaderItem" />
        <ListView
            android:id="@+id/lwShelfShare"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stackFromBottom="true"
            android:transcriptMode="normal" />
    </LinearLayout>

Screen cast

2 个答案:

答案 0 :(得分:7)

我这样想出来了。希望它有所帮助。

mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        RecyclerView recyclerView = getRecyclerView();
        if (recyclerView != null) {
            int position = getLayoutPosition();
            RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForLayoutPosition(position + 1);
            if (viewHolder == null) {
                recyclerView.smoothScrollToPosition(position + 1);
                return true;
            }
        }
        return false;
    }
});

答案 1 :(得分:0)

@Ivan Vazhnov

您需要将recyclerView的引用传递给适配器,例如

==False

,然后在适配器onBindViewHolder {}内

CustomAdapter(data:Object, recyclerView: RecyclerView)