Я использую RecyclerView
с LinearLayoutManager
для заполнения ArrayList
объектов. Мне нужно, как реализовать событие onFocus
, когда я изменяю фокус с элемента на элемент? onClick
Событие отлично работает, но событие onFocus
не влияет.RecyclerView onFocus event
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>
Моя кодирования реализация onFocus
в ViewHolder
класса в ListAdapter
:
@Override
public void onFocusChange(View v, boolean hasFocus) {
int position = getAdapterPosition();
if(hasFocus) {
Toast.makeText(this.ctx, "Position : " + position, Toast.LENGTH_SHORT).show();
}
}
onFocus
событие здесь не имеет никакого эффекта, она не работает. Возможно ли реализовать событие onFocus
на RecyclerView
?
Что именно я должен делать? Должен ли я добавить код из GridLayoutManager для правильной работы onFocus? – Alaron