我使用RecyclerView和LinearLayoutManager来填充对象的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>我在onFocus中ViewHolder类中的编码实现
@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事件?
发布于 2016-07-17 09:43:53
https://stackoverflow.com/questions/38419825
复制相似问题