2017-04-08 5 views
0

アダプタとViewHolderを持つRecyclerViewがあります。ViewHolderのonClickListenerが呼び出されるのは時々

public class MainListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 
    private TextView nameLabel; 

    public MainListViewHolder(View v){ 
     super(v); 

     nameLabel = (TextView) v.findViewById(R.id.nameLabel); 
     v.setOnClickListener(this); 

     context = v.getContext(); 
    } 



    public void bindEvent(Event e){ 
     nameLabel.setText(e.getName().toUpperCase()); 
    } 

    @Override 
    public void onClick(View view) { 
     Log.v(TAG, "ViewHolder onClick triggered"); 
     Intent intent = new Intent(context, EventViewPagerActivity.class); 
     context.startActivity(intent); 
    } 

しかし、onClickは時々呼び出されるだけで、実行時に特定のパターンを見つけることができません。

編集:

これをListItemのルートに追加しました。それぞれの子項目で

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingTop="20dp" 
android:paddingBottom="20dp" 
android:descendantFocusability="beforeDescendants" 
android:focusable="true" 
android:focusableInTouchMode="true"> 

android:focusableInTouchMode="false" 

これは残念なことです。

+0

1でのルート項目にこれを追加してみてください。 – Wizard

+0

私はlistitem全体をクリック可能と思っています。 – Bioaim

+0

ええ、しかし、子供の1つがフォーカスを保持している必要があります。それぞれの子アイテムに 'focusableInTouchMode =" false "'を追加してみてください。 – Wizard

答えて

0

あなたViewHolderの一部の子ビューがフォーカス可能である、あなたのViewHolderレイアウトXML v`がフォーカスを保持しなければならない `の子ビューの

android:descendantFocusability="beforeDescendants" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
+0

最初の投稿を編集しました – Bioaim

関連する問題