У меня есть карточка и я пытаюсь написать к ней адаптер. Как правильно написать onBindViewHolder в адаптере?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RecyclerView recyclerView = (RecyclerView) inflater.inflate(
R.layout.recycler_view, container, false);
ContentAdapter adapter = new ContentAdapter(recyclerView.getContext());
recyclerView.setAdapter(adapter);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return recyclerView;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView cvUser;
TextView cvLocation;
ImageView cvPhoto;
TextView cvContent;
public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
super(inflater.inflate(R.layout.card_feed, parent, false));
cv = (CardView) itemView.findViewById(R.id.card_view);
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);
}
}
public static class ContentAdapter extends RecyclerView.Adapter<ViewHolder> {
// Установим количество элементов списка в RecyclerView.
private static final int LENGTH = 18;
public ContentAdapter(Context context) {
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return LENGTH;
}
}
}