gpt4 book ai didi

android - 如何获取 RecyclerView.Adapter 中的卡片位置?

转载 作者:太空狗 更新时间:2023-10-29 16:30:45 25 4
gpt4 key购买 nike

请帮我解决一个问题。问题是我需要获取卡片位置以将此位置传达给另一个 Activity。当我按下卡上的按钮时,我需要转移这个位置。如何获取卡片位置?

RVAdapter.java

public class RVAdapter extends RecyclerView.Adapter<RVAdapter.PersonViewHolder> {

private final static String myLog = "myLog";


List<ItemsOfRow> items;
private Context context;


RVAdapter(List<ItemsOfRow> items, Context context) {
this.items = items;
this.context = context;
}

@Override
public int getItemCount() {
return items.size();
}

@Override
public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view, viewGroup, false);
PersonViewHolder pvh = new PersonViewHolder(v);
return pvh;
}

@Override
public void onBindViewHolder(PersonViewHolder personViewHolder, int i) {


personViewHolder.imgGroupImage.setImageBitmap(items.get(i).getTitleImage());
personViewHolder.txtTitleGroup.setText(items.get(i).getTitleName());
personViewHolder.txtContentGroup.setText(items.get(i).getTitleContent());


personViewHolder.btnShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, items.get(????).getTitleContent());
sendIntent.setType("text/plain");
context.startActivity(sendIntent);
}
});

personViewHolder.btnLearnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, QuoteActivity.class);
intent.putExtra("title",items.get(?????).getTitleName());
intent.putExtra("positionGroup", ?????? + "");
view.getContext().startActivity(intent);
}
});

}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}

public static class PersonViewHolder extends RecyclerView.ViewHolder{

CardView cv;

TextView txtTitleGroup;
TextView txtContentGroup;

ImageView imgGroupImage;

Button btnShare;
Button btnLearnMore;


PersonViewHolder(final View itemView) {
super(itemView);



cv = (CardView) itemView.findViewById(R.id.cv);

imgGroupImage = (ImageView) itemView.findViewById(R.id.img_group_image);
txtTitleGroup = (TextView) itemView.findViewById(R.id.txt_title_group);
txtContentGroup = (TextView) itemView.findViewById(R.id.txt_content_group);


btnShare = (Button) itemView.findViewById(R.id.btn_share_group);
btnLearnMore = (Button) itemView.findViewById(R.id.btn_learn_more);


}
}
}

最佳答案

您可以使用 viewHolder 的方法 getAdapterPosition()

关于android - 如何获取 RecyclerView.Adapter 中的卡片位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39528391/

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