RecyclerView 问题:EditText 失去焦点 [英] RecyclerView issues: EditText loses focus
问题描述
我在 RecyclerView
中放入了一些 EditText
因为我需要获取一些值.实现是这样的:
I've put some EditText
in RecyclerView
because I need to get some values. The implementation is this:
<android.support.v7.widget.RecyclerView
android:layout_below="@id/firstrow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/rectable"
android:layout_marginLeft="@dimen/table_margin"
android:layout_marginRight="@dimen/table_margin"
android:layout_marginBottom="300dp" />
这是带有一些editText
的自定义xml:
and this is the custom xml with some editText
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white"
android:orientation="horizontal"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="60dp ">
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/description"
android:layout_weight="1"
android:textColor="@color/black" />
<View
style="@style/VerticalSeparator" />
<EditText
android:hint="lol"
android:id="@+id/weight"
android:focusable="true"
style="@style/DefaultEditCellStyle" />
<View
style="@style/VerticalSeparator" />
<EditText
android:hint="lol"
android:id="@+id/arm"
android:focusable="true"
style="@style/DefaultEditCellStyle" />
<View
style="@style/VerticalSeparator" />
<EditText
android:hint="lol"
android:focusable="true"
android:id="@+id/moment"
style="@style/DefaultEditCellStyle" />
实际上,当我单击 EditText
时,它会打开键盘,失去焦点并立即关闭键盘,因此无法在其中进行编写.我也试过阅读其他问题,把这个:
practically when I click on an EditText
it opens keyboard, lose focus and close keyboard immediately, so it's impossible to write in these. I also tried reading other question, to put this:
recyclerView.setFocusable(true);
recyclerView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
recyclerView.setAdapter(adapter);
但是,与 listview
不同,它不起作用.
but, at different of listview
, it doesn't work.
我该如何解决这个问题?谢谢
How could I solve this issue? Thank you
推荐答案
最后我用这个解决了:
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
在 RecyclerView 的布局中,我将它添加到清单中:
in RecyclerView's layout and I add it in the Manifest:
android:windowSoftInputMode="stateHidden|adjustPan"
这篇关于RecyclerView 问题:EditText 失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!