首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RecyclerView onFocus事件

RecyclerView onFocus事件
EN

Stack Overflow用户
提问于 2016-07-17 09:34:11
回答 1查看 4.1K关注 0票数 3

我使用RecyclerViewLinearLayoutManager来填充对象的ArrayList。当我将焦点从一个项目更改到另一个项目时,我需要的是如何实现onFocus事件?onClick事件可以正常工作,但是onFocus事件没有任何效果。

XML:

代码语言:javascript
复制
<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>

我在onFocusViewHolder类中的编码实现

代码语言:javascript
复制
@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事件?

EN

回答 1

Stack Overflow用户

发布于 2016-07-17 09:43:53

看看这个有用吗。我发现有点类似于你的问题。

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38419825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档