簡體   English   中英

RecyclerView內EditText中的InputType

[英]InputType in EditText inside RecyclerView

在我的RecyclerrView有些項目具有EditText(Inside cardView)它在沒有在EditText定義InputType情況下可以正常工作,但是當我定義InputType時,當EditText成為焦點時(當在editTexteditText以輸入值時)它會使recyclerview滾動到位置零。

這是默認的EditText ,可以正常工作

 <EditText
        android:id="@+id/et_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/dp_5"
        android:layout_weight="1"
        android:background="@drawable/box_blue_outline"
        android:gravity="center"
        android:hint="@string/name"
        android:padding="@dimen/dp_5"
        android:textSize="@dimen/sp_16" />

我還有另一個僅接受數字的EditText ,所以我添加了InputType

  <EditText
    android:id="@+id/et_name"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/dp_5"
    android:layout_weight="1"
    android:background="@drawable/box_blue_outline"
    android:gravity="center"
    android:inputType="number"
    android:hint="@string/number"
    android:padding="@dimen/dp_5"
    android:textSize="@dimen/sp_16" />

但是單擊此EditText以輸入值,該值在RecyclerView之間(例如7)處於某個位置,它將滾動回到位置1。

看起來,不同的鍵盤更改導致RecyclerView更新。 Window焦點類型很有可能。 嘗試更改鍵盤行為,使其出現在Activity/Fragment onCreate

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

請包括所有View布局, RecyclerView以及要綁定的布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM