Answer the question
In order to leave comments, you need to log in
Restoring content in CardView after rotation?
Good!
Cards are created, LinearLayout is added to them, LinearLayout has its own content. When the device is rotated, the cards are recreated naturally, I try to add the previously created LinearLayout to the new cards in order to restore the content. Accordingly, I run into an error that the LinearLayout already has a parent. Where and how can I remove a link to old cards in the adapter, or how is it better to implement it?
@Override
public void onBindViewHolder(FineFoodHolder holder, int position) {
if (AddItemMenu.getInstance().getLayoutArrayList().size() != data.size()) {
holder.layout = new LinearLayout(holder.cardView.getContext());
holder.layout.setId(position);
AddItemMenu.getInstance().addCardItem(position);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
holder.layout.setOrientation(LinearLayout.VERTICAL);
holder.layout.setLayoutParams(params);
holder.cardView.addView(holder.layout);
View viewPlus = new ItemPlus().onCreateView((LayoutInflater) holder.layout.getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE), holder.layout, new Bundle());
holder.layout.addView(viewPlus);
AddItemMenu.getInstance().getLayoutArrayList().add(holder.layout); //отдельный класс синглтон, в котором храню ArrayList<LinearLayout>
} else {
holder.cardView.addView(AddItemMenu.getInstance().getLayoutArrayList().get(position));//тут пытаюсь заполнить новые карточки данными
}
}
@Override
public int getItemCount() {
return data.size();
}
public static class FineFoodHolder extends RecyclerView.ViewHolder {
protected View view;
private CardView cardView;
private LinearLayout layout;
public FineFoodHolder(final View itemView) {
super(itemView);
cardView = (CardView) itemView.findViewById(R.id.card_view);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question