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"
。
これは残念なことです。
1でのルート項目にこれを追加してみてください。 – Wizard
私はlistitem全体をクリック可能と思っています。 – Bioaim
ええ、しかし、子供の1つがフォーカスを保持している必要があります。それぞれの子アイテムに 'focusableInTouchMode =" false "'を追加してみてください。 – Wizard