Has anyone using RecyclerView found a way to set an onClickListener to items in the RecyclerView? I thought of setting a listener to each of the layouts for each item but that seems a little too much hassle I'm sure there is a way for the RecyclerView to listen for the onClick event but I can't quite figure it out.
ViewHolder.java
import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
public class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout linearLayout;
View mView;
public ViewHolder(View itemView) {
super(itemView);
this.mView = itemView;
}
public void setDetails(Context ctx, String title, String desc, String image) {
Typeface typeface = Typeface.createFromAsset(ctx.getAssets(), "Cairo.ttf");
Typeface typeface1;
typeface1 = Typeface.createFromAsset(ctx.getAssets(), "semibold.ttf");
TextView txt_title = mView.findViewById(R.id.txt_title);
ImageView imageView = mView.findViewById(R.id.image_card);
TextView txt_desc = mView.findViewById(R.id.txt_desc);
txt_title.setText(title);
txt_desc.setText(desc);
Picasso.get().load(image).into(imageView);
txt_title.setTypeface(typeface1);
txt_desc.setTypeface(typeface);
}
}