我正在使用带有 LinearLayoutManager
的 RecyclerView
来填充对象的 ArrayList
。我需要的是当我将焦点从一个项目切换到另一个项目时,如何实现 onFocus
事件? onClick
事件工作正常,但 onFocus
事件无效。
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>
我在 ListAdapter
的 ViewHolder
类中实现了 onFocus
:
@Override
public void onFocusChange(View v, boolean hasFocus) {
int position = getAdapterPosition();
if(hasFocus) {
Toast.makeText(this.ctx, "Position : " + position, Toast.LENGTH_SHORT).show();
}
}
这里的onFocus
事件没有作用,不起作用。是否可以在 RecyclerView
上实现 onFocus
事件?
最佳答案
关于android - RecyclerView onFocus 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419825/