3

I am using a RecyclerView with a LinearLayoutManager to populate an ArrayList of objects. What I need is how to implement the onFocus event when I change the focus from item to item? onClick event works fine, but the onFocus event has no effect.

XML:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listchannels"
    android:layout_width="600dp"
    android:layout_height="560dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="30dp">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/channelList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:focusable="true"
        android:focusableInTouchMode="true"/>

</FrameLayout>

My coding implementation of onFocus within the ViewHolder class in the ListAdapter:

@Override
public void onFocusChange(View v, boolean hasFocus) {
    int position = getAdapterPosition();

    if(hasFocus) {
        Toast.makeText(this.ctx, "Position : " + position, Toast.LENGTH_SHORT).show();
    }
}

The onFocus event here has no effect, it doesn't work. Is it possible to implement the onFocus event on a RecyclerView?

Daniel
  • 2,355
  • 9
  • 23
  • 30
erimeri
  • 181
  • 1
  • 3
  • 17

1 Answers1

0

Check if this helps. I found somewhat similar to your issue.

https://stackoverflow.com/a/33190656/2779404

If not, let me try providing another approaches.

Community
  • 1
  • 1
Prashant
  • 188
  • 4
  • What exactly should i do? Should i add the code from GridLayoutManager in order the onFocus to function properly? – erimeri Jul 17 '16 at 11:08