Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView issues: EditText loses focus

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

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

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);

but, at different of listview, it doesn't work.

How could I solve this issue? Thank you

like image 672
ste9206 Avatar asked Feb 08 '17 10:02

ste9206


1 Answers

Finally I've solved it using this:

 android:focusableInTouchMode="true"
 android:descendantFocusability="beforeDescendants"

in RecyclerView's layout and I add it in the Manifest:

android:windowSoftInputMode="stateHidden|adjustPan"
like image 159
ste9206 Avatar answered Oct 14 '22 06:10

ste9206