Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import java.util.ArrayList; public class MessagesAdapter extends RecyclerView.Adapter<MessagesAdapter.ViewHolder> { private SearchFragment mContext; private ArrayList<ChatRoom> chatRoomArrayList; private static String today; public class ViewHolder extends RecyclerView.ViewHolder { public TextView name, message, timestamp, count; public ViewHolder(View view) { super(view); name = (TextView) view.findViewById(R.id.name); message = (TextView) view.findViewById(R.id.message); timestamp = (TextView) view.findViewById(R.id.timestamp); count = (TextView) view.findViewById(R.id.count); } } public MessagesAdapter(SearchFragment mContext, ArrayList<ChatRoom> chatRoomArrayList) { this.mContext = mContext; this.chatRoomArrayList = chatRoomArrayList; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.chat_rooms_list_row, parent, false); return new ViewHolder(itemView); } @Override public void onBindViewHolder(ViewHolder holder, int position) { ChatRoom chatRoom = chatRoomArrayList.get(position); holder.name.setText(chatRoom.getName()); holder.message.setText(chatRoom.getLastMessage()); holder.timestamp.setText(chatRoom.getTimestamp()); holder.count.setText(chatRoom.getUnreadCount()); } @Override public int getItemCount() { return chatRoomArrayList.size(); } }