RecyclerView adapter shows a blank map view

I have a nasty problem on sub api21 devices. I am using the RecyclerView.Adapter adapter to inflate android.support.v7.widget.CardView. The idea is that the cards will only add information that is present on the cards. If no information is available, the map will not be displayed at all. Therefore, I create these cards programmatically.

Here are the screenshots on api21 and api19 api21api19

Notice how api19 shows cards that have no values. I believe the problem is caused by the adapter calling onCreateViewHolder with no values. Is there any way around onCreate? or onBind? Or is there a way to work a bit with sub api21 cards?

CardView XML

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="true"
card_view:cardCornerRadius="5dp"
android:layout_margin="5dp"
card_view:cardUseCompatPadding="true">

<LinearLayout
    android:id="@+id/card_info_lin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"/>

Adapter

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
   switch(viewType) {
       case VIEW_ENGINE:
            itemViewEngine = LayoutInflater
                    .from(viewGroup.getContext())
                    .inflate(R.layout.card_info, viewGroup, false);
            cardInfo.clear();

            return new ViewHolderEngine(itemViewEngine, cardInfo);

        case VIEW_TIRES:
            itemViewTires = LayoutInflater
                    .from(viewGroup.getContext())
                    .inflate(R.layout.card_info, viewGroup, false);
            cardInfo.clear();

            return new ViewHolderTires(itemViewTires, cardInfo);

        default: //General
            itemViewGeneral = LayoutInflater
                    .from(viewGroup.getContext())
                    .inflate(R.layout.card_info, viewGroup, false);
            cardInfo.clear();

            return new ViewHolderGeneral(itemViewGeneral, cardInfo);
    }
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
    cardInfo = vehicleInfo.get(i);
    switch (getItemViewType(i)) {
        case VIEW_GENERAL:
            new ViewHolderGeneral(itemViewGeneral, cardInfo);

            break;

        case VIEW_ENGINE:
            new ViewHolderEngine(itemViewEngine, cardInfo);

            break;

        case VIEW_TIRES:
            new ViewHolderTires(itemViewTires, cardInfo);

            break;
        }
    }
}

Owner's class (1 of 3)

    class ViewHolderGeneral extends RecyclerView.ViewHolder {
        private static final String TAG = "adapter_info_ViewHolder_gen";

        private TypedArray headerColors;
        private ArrayList<String> labels = new ArrayList<>();

        public ViewHolderGeneral(View view, final ArrayList<String> cardInfo) {
            super(view);

            View layout = view.findViewById(R.id.card_info_lin);

            DisplayMetrics metrics = layout.getContext().getResources().getDisplayMetrics();

...set up cards
+3
1

, , , CardView / sub API21. , , , , . , , , ( .)

+3

Source: https://habr.com/ru/post/1623236/


All Articles