2016-07-17 6 views
0

LinearLayoutManagerRecyclerViewを使用して、ArrayListのオブジェクトを設定しています。フォーカスをアイテムからアイテムに変更するときに、onFocusイベントを実装する方法が必要です。 onClickイベントは正常に機能しますが、onFocusイベントは無効です。RecyclerView onFocusイベント

XML:ListAdapterViewHolderクラス内onFocus

<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> 

私のコーディングの実装:

@Override 
public void onFocusChange(View v, boolean hasFocus) { 
    int position = getAdapterPosition(); 

    if(hasFocus) { 
     Toast.makeText(this.ctx, "Position : " + position, Toast.LENGTH_SHORT).show(); 
    } 
} 

ここonFocusイベントは効果がありません、それは動作しません。 RecyclerViewonFocusイベントを実装することはできますか?

答えて

0

これが役立つかどうかを確認してください。私はあなたの問題に多少似ています。

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

ない場合は、私は別のアプローチを提供してみましょう。

+0

私は正確に何をすべきですか? onFocusが正しく機能するために、GridLayoutManagerからコードを追加する必要がありますか? – Alaron

関連する問題