public class ContentAdapter extends RecyclerView.Adapter<ContentAdapter.ViewHolder> {
private List<CardFeed> cardfeedlist;
public ContentAdapter(List<CardFeed> cardfeed) {
this.cardfeedlist = cardfeed;
}
private static final int LENGTH = 18;
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView cvUser;
TextView cvLocation;
ImageView cvPhoto;
TextView cvContent;
public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
super(inflater.inflate(R.layout.card_feed, parent, false));
cvUser = (TextView) itemView.findViewById(R.id.card_user);
cvLocation = (TextView) itemView.findViewById(R.id.card_location);
cvPhoto = (ImageView) itemView.findViewById(R.id.card_image);
cvContent = (TextView) itemView.findViewById(R.id.card_text);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
CardFeed cardfeed = cardfeedlist.get(position);
holder.cvUser.setText(cardfeed.getName());
holder.cvLocation.setText(cardfeed.getLocation());
holder.cvContent.setText(cardfeed.getDescription());
holder.cvPhoto.setImageResource(cardfeed.getPhoto());
}
@Override
public int getItemCount() {
if(cardfeedlist==null) return 0;
return cardfeedlist.size();
}
public void swapCardfeeds(List<CardFeed> cardfeedlist){
this.cardfeedlist= cardfeedlist;
notifyDataSetChanged();
}
}
private List<CardFeed> cardfeed;
public ContentAdapter(List<CardFeed> cardfeed) {
this.cardfeed = cardfeed;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
CardFeed cardfeed = cardfeeds.get(position);
holder.cvUser.setText(cardfeed.getName());
holder.cvLocation.setText(cardfeed.getLocation());
holder.cvContent.setText(cardfeed.getDescription());
holder.cvPhoto.setImageResource(cardfeed.getPhoto());
}
CardFeed cardfeed = cardfeeds.get(position);
public class CardFeed {
private String name;
private String location;
private String description;
private int photo;
public CardFeed(){
}
public CardFeed(String name, String location, String description, int photo) {
this.name = name;
this.location = location;
this.description = description;
this.photo = photo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getPhoto() {
return photo;
}
public void setPhoto(int photo) {
this.photo = photo;
}
}
private List<CardFeed> cardfeed;
public ContentAdapter(List<CardFeed> cardfeed) {
this.cardfeed = cardfeed;
}