Это мой код:
Код: Выделить всё
recBlockList=new ArrayList();
List cc = new ArrayList();
Card1 cac = new Card1("المنتج", 10, 10, 0,
R.drawable.image1);cc.add(cac);linearLayoutManager2=new LinearLayoutManager(requireContext());linearLayoutManager2.setOrientation(LinearLayoutManager.VERTICAL);verticalRecyclerView.setLayoutManager(linearLayoutManager2);
RecBlock firstRecBlockList = new RecBlock("qwe", "لابتوبات",
cc);recBlockList.add(firstRecBlockList);verticalAdapter=new VerticalAdapter(requireContext(),recBlockList,this);verticalRecyclerView.setAdapter(verticalAdapter);
Handler hand = new Handler(Looper.getMainLooper());
Runnable run = new Runnable() {
@Override
public void run() {
for (int i = 0; i < 1; i++) {
List cpc = new ArrayList();
Card1 capc = new Card1("المنتج", 10, 10, 0, R.drawable.image1);
cpc.add(capc);
RecBlock cap = new RecBlock("i", "هواتف" + add, cpc);
recBlockList.add(cap);
add++;
}
verticalAdapter.notifyItemInserted(recBlockList.size() - 1);
hand.postDelayed(this, 5000); // التمرير كل 3 ثوانٍ
}
};
hand.postDelayed(run, 5000);
Код: Выделить всё
public class RecBlock implements HorizontalInterface {
private String idOrType;
private String name;
private int page = 0;
private boolean loading = false;
public List card1List;
public HorizontalAdapter horizontalAdapter;
public RecBlock(String idOrType, String name, List card1List) {
this.idOrType = idOrType;
this.name = name;
this.card1List = card1List;
horizontalAdapter = new HorizontalAdapter(card1List, RecBlock.this);
}`
public class VerticalAdapter extends RecyclerView.Adapter
implements HorizontalInterface {
List recBlockList;
VerticalInterface verticalInterface;
Context context;
LinearLayoutManager linearLayoutManager;
public VerticalAdapter(Context context, List recBlockList, VerticalInterface verticalInterface) {
this.recBlockList = recBlockList;
this.verticalInterface = verticalInterface;
this.context = context;
}...
@Override
public void onBindViewHolder(ItemViewHolder holder, int position) {
holder.nameOfRec.setText(recBlockList.get(position).getName());
holder.rec.setAdapter(recBlockList.get(position).horizontalAdapter);
verticalInterface.newRec(holder.rec, linearLayoutManager, recBlockList.get(position).horizontalAdapter,
recBlockList.get(position));
holder.openRec.setOnClickListener(v -> {
verticalInterface.open(true, recBlockList.get(position).getIdOrType());
});
}
public class ItemViewHolder extends RecyclerView.ViewHolder {
RecyclerView rec;
TextView nameOfRec;
TextView openRec;
public ItemViewHolder(View itemView) {
super(itemView);
rec = itemView.findViewById(R.id.horizontalReciclerView);
linearLayoutManager = new LinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rec.setLayoutManager(linearLayoutManager);
nameOfRec = itemView.findViewById(R.id.nameOfRec);
openRec = itemView.findViewById(R.id.openRec);
}
}
`
Оно практически вообще не меняется, потому что я распечатал тост, в котором отображается, например, пятый горизонтальный RecyclerView и это было правильно, но когда горизонтальный RecyclerView перерабатывается вертикальным RecyclerView, список размещается в другом месте.
Я считаю, что причина в том, как он определен setAdapter для горизонтального RecyclerView, но в неудачных попытках я печатал имя для каждого блока, и оно было правильным, и я печатал сквозную проверку, которая была правильной, но проблема, я думаю, в том, что из setAdapter для горизонтального RecyclerView. LinearLayoutManager выглядит полностью правильно, потому что когда я показываю всплывающие уведомления, он отображает всю свою информацию.
Подробнее здесь: https://stackoverflow.com/questions/790 ... rom-before
Мобильная версия