необходимо сделать прокрутку как в playstore, но к сожалению recycleview отображает некорректно заполняя только первый элемент списка всеми элементами.
1-й адаптер
public class CategoryRecyclerAdapter extends RecyclerView.Adapter<CategoryRecyclerAdapter.CategoryViewHolder> {
private ArrayList<CategoryReference> categoryReferences;
private ArrayList<ReferenceRecyclerAdapter> referenceRecyclerAdapters = new ArrayList<>();
private Context context;
public CategoryRecyclerAdapter(ArrayList<CategoryReference> categoryReferences, Context context) {
this.categoryReferences = categoryReferences;
this.context = context;
}
@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_reference, parent, false);
CategoryViewHolder categoryViewHolder = new CategoryViewHolder(view);
return categoryViewHolder;
}
@Override
public void onBindViewHolder(CategoryViewHolder holder, int position) {
final String categoryName = categoryReferences.get(position).getCategoryName();
ArrayList<References> referencesList = categoryReferences.get(position).getReferencesList();
holder.categoryName.setText(categoryName);
ReferenceRecyclerAdapter referenceRecyclerAdapter = new ReferenceRecyclerAdapter(referencesList);
holder.recycleItemReference.setHasFixedSize(true);
holder.recycleItemReference.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
holder.recycleItemReference.setAdapter(referenceRecyclerAdapter);
}
@Override
public int getItemCount() {
return (null != categoryReferences ? categoryReferences.size() : 0);
}
public static class CategoryViewHolder extends RecyclerView.ViewHolder {
TextView categoryName;
RecyclerView recycleItemReference;
public CategoryViewHolder(View itemView) {
super(itemView);
categoryName = itemView.findViewById(R.id.tv_category_name);
recycleItemReference = itemView.findViewById(R.id.reference_pager);
}
}
2-й адаптер
public class ReferenceRecyclerAdapter extends RecyclerView.Adapter<ReferenceRecyclerAdapter.ReferenceViewHolder> {
private ArrayList<References> referencesList;
public ReferenceRecyclerAdapter(ArrayList<References> referencesList) {
this.referencesList = referencesList;
}
@Override
public ReferenceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_previous_references, parent, false);
ReferenceViewHolder referenceViewHolder = new ReferenceViewHolder(view);
return referenceViewHolder;
}
@Override
public void onBindViewHolder(ReferenceViewHolder holder, int position) {
References itemRef = referencesList.get(position);
holder.previousImage.setImageResource(itemRef.getImgPrevious());
holder.previousText.setText(itemRef.getTxtPrevious());
}
@Override
public int getItemCount() {
return (null != referencesList ? referencesList.size() : 0);
}
public static class ReferenceViewHolder extends RecyclerView.ViewHolder {
ImageView previousImage;
TextView previousText;
public ReferenceViewHolder(View itemView) {
super(itemView);
previousImage = itemView.findViewById(R.id.img_previous);
previousText = itemView.findViewById(R.id.txt_previous);
}
}
}
Виртуальный выделенный сервер (VDS) становится отличным выбором
How to get bytes and write them in a string representation for example from Socket sent to Socket Server port 1025 a "0" character on the output to get the recorded txt file with the information "00000000" and so on for all data sent from Socket
Можно ли улучшить(упростить) данную конструкцию тернарным оператором?
Расскажите пожалуйста, как реализована потоковая модель в NIO2? Правильно ли я понимаю, что при инициализации (или первом установке Callback) создается...