"how to use more than one arraylist in recyclerview holder" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "how to use more than one arraylist in recyclerview holder" answered properly. Developers are finding an appropriate answer about how to use more than one arraylist in recyclerview holder related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like how to use more than one arraylist in recyclerview holder. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on how to use more than one arraylist in recyclerview holder.
how to use more than one arraylist in recyclerview holder
public class ChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
final int VIEW_TYPE_MESSAGE = 0;
final int VIEW_TYPE_IMAGE = 1;
Context context;
List<ChatWrapper> messages;
List<ImageDataWrapper> images;
public ChatAdapter(Context context, List<ChatWrapper> messages, List<ImageDataWrapper> images){
this.context = context;
this.messages = messages;
this.images = images;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
if(viewType == VIEW_TYPE_MESSAGE){
return new MessageViewHolder(itemView);
}
if(viewType == VIEW_TYPE_IMAGE){
return new ImageViewHolder(itemView);
}
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position){
if(viewHolder instanceof MessageViewHolder){
((MessageViewHolder) viewHolder).populate(messages.get(position));
}
if(viewHolder instanceof ImageViewHolder){
((ImageViewHolder) viewHolder).populate(images.get(position - messages.size()));
}
}
@Override
public int getItemCount(){
return messages.size() + images.size();
}
@Override
public int getItemViewType(int position){
if(position < messages.size()){
return VIEW_TYPE_MESSAGE;
}
if(position - messages.size() < images.size()){
return VIEW_TYPE_IMAGE;
}
return -1;
}
public class MessageViewHolder extends RecyclerView.ViewHolder {
TextView message;
TextView timeStamp;
ImageView userImage;
public MessageViewHolder(View itemView){
super(itemView);
message = (TextView) itemView.findViewById(R.id.Single_Item_Chat_Message);
timeStamp = (TextView) itemView.findViewById(R.id.Single_Item_Chat_TimeStamp);
userImage = (ImageView) itemView.findViewById(R.id.Single_Item_Chat_ImageView);
}
public void populate(ChatWrapper chatWrapper){
message.setText(chatWrapper.getMessage());
userImage.setText(chatWrapper.getTimestamp());
}
}
public class ImageViewHolder extends RecyclerView.ViewHolder {
TextView dataTitle;
TextView dataLink;
TextView dataSnippet;
ImageView image;
ImageButton dataSendButton;
public ImageViewHolder(View itemView){
super(itemView);
dataTitle = (TextView) itemView.findViewById(R.id.Image_data_Title);
dataLink = (TextView) itemView.findViewById(R.id.Image_data_Link);
dataSnippet = (TextView) itemView.findViewById(R.id.Image_data_Snippet);
image = (ImageView) itemView.findViewById(R.id.Image_data_Image);
dataSendButton = (ImageButton) itemView.findViewById(R.id.Image_data_SendButton);
}
public void populate(ImageDataWrapper imageDataWrapper){
dataTitle.setText(imageDataWrapper.getPage_Title());
dataLink.setText(imageDataWrapper.getPage_Link());
dataSnippet.setText(imageDataWrapper.getPage_Desc());
Picasso.with(context).load(imageDataWrapper.getPage_ImageThumb()).into(image);
}
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on how to use more than one arraylist in recyclerview holder can get a collection of related answers to their query. Programmers need to enter their query on how to use more than one arraylist in recyclerview holder related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to use more than one arraylist in recyclerview holder for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of how to use more than one arraylist in recyclerview holder while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "how to use more than one arraylist in recyclerview holder". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to use more than one arraylist in recyclerview holder resolved professionally and stay updated to the latest Whatever updates.