RecyclerView Viewholder点击无效。我使用LinearLayoutManager作为recyclerview。在recyclerview视图中没有触发clcik事件。我错过了什么,这是我的ViewHolder
public class FeedViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
@Bind(R.id.imgNewUser) CircularImageView imgUser;
@Bind(R.id.txtUserNameNewUser) TextView txtUserNameNewUser;
@Bind(R.id.txtNewUserPostCount) TextView txtNewUserPostCount;
@Bind(R.id.btnFollowNewUser) Button btnFollowNewUser;
public FeedViewHolder(View view) {
super(view);
view.setOnClickListener(this);
ButterKnife.bind(this,view);
}
@Override
public void onClick(View v){
Toast.makeText(mContext,"Hello",Toast.LENGTH_SHORT);
onFollowListener.onFollow(getAdapterPosition());
}
}
膨胀的行布局,
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/tools"
card_view:cardElevation="3dp"
android:clickable="true"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true">
<LinearLayout
android:layout_toLeftOf="@+id/btnFollowNewUser"
android:orientation="horizontal"
android:layout_margin="10dp"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.petmire.petmireapp.common.CircularImageView
android:id="@+id/imgNewUser"
android:src="@drawable/ic_launcher"
android:layout_width="50dp"
android:layout_height="50dp"
app:border_width="0.5dp"
app:border_color="@android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txtUserNameNewUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:textColor="@color/colorPrimaryDark"
android:fontFamily="sans-serif-light"
android:text="Petmireapp1"/>
<TextView
android:id="@+id/txtNewUserPostCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:textSize="14sp"
android:textColor="@color/colorPrimary"
android:fontFamily="sans-serif-light"
android:text="26 Posts"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/btnFollowNewUser"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:fontFamily="sans-serif-light"
android:text="Follow"
android:clickable="true"
android:background="@drawable/btn_follow_shape"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
帮我解决这个问题。