0

I have a recycler view and its row is set to (focusable="true") so that i can animate its row through d-pad controls on focus which is working great.But when i press enter it doesn't detect click on recycler view's child which is annoying.

My recycler view code :

<android.support.v7.widget.RecyclerView
            android:id="@+id/featuredRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:focusable="false"
            android:clipChildren="false"
            >
        </android.support.v7.widget.RecyclerView>

My RecyclerView row layout :

<com.open.androidtvwidget.leanback.widget.OpenCardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card"
android:background="@color/white"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:descendantFocusability="beforeDescendants"
>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    >

    <ImageView
        android:id="@+id/ivMovie"
        android:layout_width="100dp"
        android:layout_height="150dp"
        android:scaleType="centerCrop"
        android:background="@color/placeholder"
        android:focusable="false"
        android:focusableInTouchMode="false"

        />

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/linear_gradiant"
        android:layout_alignRight="@+id/ivMovie"
        android:layout_alignLeft="@+id/ivMovie"
        android:layout_alignBottom="@+id/ivMovie">

        <TextView
            android:id="@+id/runtime_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1m"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:gravity="center"
            android:layout_marginRight="3dp"
            />

    </RelativeLayout>
</RelativeLayout>


</com.open.androidtvwidget.leanback.widget.OpenCardView>

My Adapter onBindViewHolder :

public void onBindViewHolder(MyViewHolder holder, final int position) {


        holder.ivMovie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent go = new Intent(mContext,LoginActivity.class);
                go.putExtra("movie", movie);
                mContext.startActivity(go);

            }
        });

    holder.card.setOnFocusChangeListener(new     View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                    v.animate().scaleX(1.2f).scaleY(1.2f).setDuration(300).start();
                v.setElevation(20);
            } else {
                v.animate().scaleX(1.0f).scaleY(1.0f).setDuration(300).start();
                v.setElevation(0);

            }
        }
    });

}

P.S : i have tried all possibilities of focusable="true/false",focusableInTouchMode="true/false",clickable="true/false" and android:descendantFocusability every where.

Hussnain Azam
  • 358
  • 1
  • 5
  • 14
  • 1
    have you tried using ImageButton instead of ImageView? – SteelBytes Feb 09 '17 at 01:41
  • Yes Not working behaviour is same to all UI widgets inside Recyclerview – Hussnain Azam Feb 09 '17 at 06:10
  • Can you try to attach the OnClickListener to @+id/card? – ULazdins Feb 09 '17 at 06:58
  • Working on @+id/card – Hussnain Azam Feb 09 '17 at 07:34
  • Try to check this [page](http://androidessence.com/recyclerview-vs-listview/) if it can help you. It will show you on how to add an OnClickListener inside the RecyclerView.ViewHolder. For more information, check this SO question [32779956](http://stackoverflow.com/questions/32779956) and [35584584](http://stackoverflow.com/questions/35584584). Also, I found here in this [thread](http://stackoverflow.com/questions/37786796) on how to work with RecyclerView including how to add and configure RecyclerView, how to create and understanding the ViewHolder and Adapter, and how to add a click listener – KENdi Feb 09 '17 at 15:22

0 Answers0