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
?