Ich verwende eine RecyclerView
mit einer LinearLayoutManager
, um eine ArrayList
von Objekten zu füllen. Was ich brauche, ist, wie man das onFocus
Ereignis einführt, wenn ich den Fokus von Einzelteil zu Einzelteil ändere? onClick
Ereignis funktioniert gut, aber das onFocus
Ereignis hat keine Wirkung.RecyclerView onFocus Ereignis
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>
Meine Codierung Implementierung von onFocus
innerhalb der ViewHolder
Klasse im ListAdapter
:
@Override
public void onFocusChange(View v, boolean hasFocus) {
int position = getAdapterPosition();
if(hasFocus) {
Toast.makeText(this.ctx, "Position : " + position, Toast.LENGTH_SHORT).show();
}
}
Die onFocus
Veranstaltung hier keine Wirkung hat, funktioniert es nicht. Ist es möglich, das Ereignis onFocus
auf einem RecyclerView
zu implementieren?
Was genau soll ich tun? Sollte ich den Code aus GridLayoutManager hinzufügen, damit der onFocus ordnungsgemäß funktioniert? – Alaron