android - RecyclerView onFocus 事件

标签 android android-recyclerview onfocus

我正在使用带有 LinearLayoutManagerRecyclerView 来填充对象的 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>

我在 ListAdapterViewHolder 类中实现了 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 事件?

最佳答案

检查这是否有帮助。我发现与您的问题有些相似。

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

如果没有,让我尝试提供另一种方法。

关于android - RecyclerView onFocus 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419825/

相关文章:

jQuery - 窗口焦点、模糊事件未触发 - 适用于 Firefox 和 Chrome

android - 如何从android中的可绘制文件夹中获取图像?

java - SQLite 查询 - 出现多次并按出现次数排序的单个记录的简短列表?

Android 排行榜不会显示

android - 使用 FirestoreRecyclerAdapter 的 Firestore 分页 (Android)

android - RecyclerView Horizo​​ntal Scrollview example 如何创建水平recyclerview?水平 ScrollView 示例

Android水平RecyclerView滚动方向

javascript - 我想将光标放在文本框 onfocus 的开头

wpf - 当焦点来自后面的代码时,如何选择 WPF TextBox 中的所有文本?

android - 如何在警报对话框中扩充包含 ListView 的布局?