public class MessagesAdapter extends RecyclerView.Adapter<MessagesAdapter.ViewHolder> {
private MessagesFragment mContext;
private ArrayList<MessagesObject> MessagesArrayList;
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView name, description, timestamp, count;
public ImageView avator;
public ViewHolder(View view) {
super(view);
avator = (ImageView)itemView.findViewById(R.id.item_chat_avatar);
name = (TextView) itemView.findViewById(R.id.dialog_title);
description = (TextView) itemView.findViewById(R.id.dialog_message);
timestamp = (TextView) itemView.findViewById(R.id.item_chat_date);
count = (TextView) itemView.findViewById(R.id.item_chat_unread_count);
}
}
public MessagesAdapter(MessagesFragment mContext, ArrayList<MessagesObject> MessagesArrayList) {
this.mContext = mContext;
this.MessagesArrayList = MessagesArrayList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_messege, parent, false);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
MessagesObject songs = MessagesArrayList.get(position);
Glide.with(mContext).load(R.drawable.a_avator).into(holder.avator);
holder.name.setText(songs.getMessagesName());
holder.description.setText(songs.getMessagesDescription());
holder.timestamp.setText(songs.getMessagesTime());
holder.count.setText(songs.getMessagesUnread());
}
@Override
public int getItemCount() {
return MessagesArrayList.size();
}
}
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Вот здесь ((MainAcivity)(v.getContext())).yourFunction
}
});