Вот так вот :
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.PersonViewHolder> {
public static class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv;
TextView personName;
TextView personAge;
ImageView personPhoto;
OnItemClickListener cvClickListener;
public interface OnItemClickListener{
void onItemClicked(int position);
}
PersonViewHolder(View itemView, OnItemClickListener clickListener) {
super(itemView);
cv = (CardView)itemView.findViewById(R.id.cv);
personName = (TextView)itemView.findViewById(R.id.person_name);
personAge = (TextView)itemView.findViewById(R.id.person_age);
personPhoto = (ImageView)itemView.findViewById(R.id.person_photo);
cvClickListener = clickListener;
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
cvClickListener.onItemClicked(getAdapterPosition());
А вот что сюда писать помогите ? Как реализовать переход на фрагмент re_fragment
}
}
List<Person> persons;
public RVAdapter(List<Person> persons){
this.persons = persons;
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@Override
public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
PersonViewHolder personViewHolder = new PersonViewHolder(view);
return personViewHolder;
}
@Override
public void onBindViewHolder(PersonViewHolder personViewHolder, int i) {
personViewHolder.personName.setText(persons.get(i).name);
personViewHolder.personAge.setText(persons.get(i).age);
personViewHolder.personPhoto.setImageResource(persons.get(i).photoId);
}
@Override
public int getItemCount() {
return persons.size();
}
}