Keep State RecyclerView When Keyboard Open

我的梦境 提交于 2021-02-04 08:30:08

问题


I have a case where the RecyclerView has 5 data Horizontal, when I was in the 5th data and clicked on EditText then the Keyboard appeared immediately scrolling back to the 1st Data which was very disturbing when I wanted to fill in the 5th data on th EditText, how to prevent that, so that the RecyclerView doesn't scroll automatically to the 1st data?

AndroidManifest.xml

   <activity
       android:name=".MainActivity"
       android:screenOrientation="portrait"
       android:theme="@style/AppTheme.NoActionBar"
       android:windowSoftInputMode="stateHidden|adjustResize">    
   </activity>

HomeFragment.kt

  rvMenuProduct.apply{
      layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
      adapter = MyAdapter(Data)
  }

fragment_home_product.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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/colorWhite">

    <TextView
        android:id="@+id/tvProductTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_10"
        android:layout_marginStart="@dimen/margin_10"
        android:fontFamily="@font/roboto_bold"
        android:textSize="@dimen/text_title"
        android:textColor="@color/colorPrimary"
        android:text="@string/home_product" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvMenuProduct"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:overScrollMode="never"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:listitem="@layout/fragment_home_product_item" />
</LinearLayout>

My Edit Text

<EditText
    android:id="@+id/etCartProductQuantity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="0dp"
    android:background="@drawable/home_product_item_qty"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:hint="@string/product_qty_default"
    android:imeOptions="actionDone"
    android:importantForAutofill="no"
    android:inputType="number"
    android:text="@string/product_qty_zero"
    android:textAlignment="center"
    android:textColor="@color/colorBlack"
    android:textCursorDrawable="@null" />

来源:https://stackoverflow.com/questions/64802989/keep-state-recyclerview-when-keyboard-open

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!