gpt4 book ai didi

java - 如何设置 RecycleView onClickListener()?

转载 作者:搜寻专家 更新时间:2023-11-01 08:20:05 24 4
gpt4 key购买 nike

<分区>

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);


}


}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com