Представление Recycler во фрагменте отображается в эмуляторе и на некоторых устройствах реального времени, но не отображается на некоторых устройствах реального времени - PullRequest
1 голос
/ 11 июня 2019

У меня есть вид переработчика в одном фрагменте. Окно рециркуляции отображается с элементами в эмуляторе и некоторыми устройствами реального времени, но не отображается на некоторых устройствах реального времени. Я сохранил это представление переработчика во вложенном представлении прокрутки.

Устройства, которые я могу видеть в окне рециркуляции : Один плюс 6T (9), Realme

Устройства, которые я не вижу в окне рециркуляции : Vivo (8.1), Sony Xperia Z2 (6.1)

Код моего фрагмента.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView   xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
    android:id="@+id/reminder_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="14dp"
    android:layout_marginTop="18dp"
    android:text="@string/refill_reminder"
    android:textColor="#031B54"
    android:textSize="13sp"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.cardview.widget.CardView
    android:id="@+id/refillReminder_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="14dp"
    android:layout_marginTop="9dp"
    android:layout_marginEnd="14dp"
    app:cardCornerRadius="3dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="@id/reminder_label"
    app:layout_constraintTop_toBottomOf="@id/reminder_label">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/refillName_heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="18dp"
            android:layout_marginTop="15dp"
            android:text="@string/refill_name"
            android:textColor="#090909"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/refillName_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/refillName_heading"
            android:layout_marginStart="48dp"
            android:layout_marginEnd="87dp"
            android:layout_toEndOf="@id/refillName_heading"
            android:text="@string/metamorphine"
            android:textColor="#090909"
            android:textSize="15sp"
            android:textStyle="normal" />

        <TextView
            android:id="@+id/refillDueIn_heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/refillName_heading"
            android:layout_alignStart="@id/refillName_heading"
            android:layout_marginTop="3dp"
            android:text="@string/refill_due_in"
            android:textColor="#090909"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/refillDueIn_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@id/refillName_label"
            android:layout_alignBottom="@id/refillDueIn_heading"
            android:text="@string/_28_days"
            android:textColor="#090909"
            android:textSize="15sp"
            android:textStyle="normal" />

        <TextView
            android:id="@+id/nextRefillDate_heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/refillDueIn_heading"
            android:layout_alignStart="@id/refillDueIn_heading"
            android:layout_marginTop="3dp"
            android:layout_marginBottom="12dp"
            android:text="@string/next_refill_date"
            android:textColor="#090909"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/nextRefillDate_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@id/refillDueIn_label"
             android:layout_alignBottom="@id/nextRefillDate_heading"
            android:text="@string/_12_5_2019"
            android:textColor="#090909"
            android:textSize="15sp"
            android:textStyle="normal" />

    </RelativeLayout>

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
    android:id="@+id/prescriptionHistory_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="14dp"
    android:layout_marginTop="13dp"
    android:layout_marginEnd="14dp"
    app:cardCornerRadius="3dp"
    app:layout_constraintEnd_toEndOf="@id/refillReminder_card"
    app:layout_constraintStart_toStartOf="@id/refillReminder_card"
    app:layout_constraintTop_toBottomOf="@id/refillReminder_card">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/history_image"
            android:layout_width="30dp"
            android:layout_height="32dp"
            android:layout_marginStart="13dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:background="@drawable/ic_history"
            android:contentDescription="TODO" />

        <TextView
            android:id="@+id/history_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginStart="20dp"
            android:layout_toEndOf="@id/history_image"
            android:text="@string/prescription_history"
            android:textColor="#031B54"
            android:textSize="17sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/prescriptionHistory_button"
            android:layout_width="20dp"
            android:layout_height="25dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/ic_arrow_right_b" />

    </RelativeLayout>

</androidx.cardview.widget.CardView>

<TextView
    android:id="@+id/myMedicines_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="19dp"
    android:layout_marginStart="14dp"
    android:text="@string/my_medicines"
    android:textColor="#031B54"
    android:textSize="13sp"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
     app:layout_constraintTop_toBottomOf="@id/prescriptionHistory_card" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/myMedicines_RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:elevation="5dp"
    android:layout_marginStart="14dp"
    android:layout_marginEnd="14dp"
    android:scrollbarStyle="insideInset"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/myMedicines_label"
    app:layout_constraintEnd_toEndOf="parent"
    android:nestedScrollingEnabled="false">

</androidx.recyclerview.widget.RecyclerView>

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

RecylerView CARD.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/myMedicines_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="3dp"
android:elevation="3dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/dosageForm_icon"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="28dp"
        android:layout_marginTop="16dp"
        android:contentDescription="TODO" />

    <TextView
        android:id="@+id/dosage_startDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/dosageForm_icon"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:text="@string/apr_22_2019"
        android:textColor="#404040"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/dosage_endDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/dosage_startDate"
        android:layout_alignStart="@id/dosage_startDate"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="10dp"
        android:text="@string/apr_30_2019"
        android:textColor="#404040"
        android:textStyle="bold"/>

    <View
        android:id="@+id/verticalSeperator_view"
        android:layout_width="13dp"
        android:layout_height="130dp"
        android:layout_marginStart="30dp"
        android:layout_toEndOf="@id/dosageForm_icon"
        android:background="@drawable/ic_seperator" />

    <TextView
        android:id="@+id/refillName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:layout_toEndOf="@id/verticalSeperator_view"
        android:text="@string/metamorphine"
        android:textColor="#404040"
        android:textSize="14dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button"
        android:layout_width="22dp"
        android:layout_height="18dp"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="7dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/ic_more_horiz" />

    <RelativeLayout
        android:id="@+id/weekday_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/refillName"
        android:layout_alignStart="@id/refillName"
        android:layout_marginTop="17dp"
        android:layout_toEndOf="@id/verticalSeperator_view">

        <TextView
            android:id="@+id/sunday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/su"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/monday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/sunday_label"
            android:layout_marginStart="7dp"
            android:layout_toEndOf="@id/sunday_label"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/mo"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/tuesday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/sunday_label"
            android:layout_marginStart="7dp"
            android:layout_toEndOf="@id/monday_label"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/tu"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/wednesday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/sunday_label"
            android:layout_marginStart="7dp"
            android:layout_toEndOf="@id/tuesday_label"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/we"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/thursday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/sunday_label"
            android:layout_marginStart="7dp"
            android:layout_toEndOf="@id/wednesday_label"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/th"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/friday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/sunday_label"
            android:layout_marginStart="7dp"
            android:layout_toEndOf="@id/thursday_label"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/fr"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/saturday_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/sunday_label"
            android:layout_marginStart="7dp"
            android:layout_toEndOf="@id/friday_label"
            android:background="@drawable/weekday_bg_grey"
            android:text="@string/sa"
            android:gravity="center"
            android:textSize="12sp"
            android:textColor="#FFFFFF" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/timeline_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/weekday_view"
        android:layout_alignStart="@id/weekday_view"
        android:layout_marginTop="5dp">

        <RelativeLayout
            android:id="@+id/view1"
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:layout_marginStart="5dp">

            <View
                android:id="@+id/horizontalSeperator_view1"
                android:layout_width="wrap_content"
                android:layout_height="2dp"
                android:layout_marginTop="34dp"
                android:background="#FBFBFB" />

            <TextView
                android:id="@+id/time1_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:textSize="10sp" />

            <View
                android:id="@+id/subview1"
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_below="@id/time1_label"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="6dp"
                android:background="@drawable/timeline_bg_color" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/view2"
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:layout_toEndOf="@id/view1">

            <View
                android:id="@+id/horizontalSeperator_view2"
                android:layout_width="wrap_content"
                android:layout_height="2dp"
                android:layout_marginTop="34dp"
                android:background="#FBFBFB" />

            <TextView
                android:id="@+id/time2_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:textSize="10sp" />

            <View
                android:id="@+id/subview2"
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_below="@id/time2_label"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="6dp"
                android:background="@drawable/timeline_bg_color" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/view3"
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:layout_toEndOf="@id/view2">

            <View
                android:id="@+id/horizontalSeperator_view3"
                android:layout_width="wrap_content"
                android:layout_height="2dp"
                android:layout_marginTop="34dp"
                android:background="#FBFBFB" />

            <TextView
                android:id="@+id/time3_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:textSize="10sp" />

            <View
                android:id="@+id/subview3"
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_below="@id/time3_label"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="6dp"
                android:background="@drawable/timeline_bg_color" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/view4"
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:layout_toEndOf="@id/view3">

            <View
                android:id="@+id/horizontalSeperator_view4"
                android:layout_width="wrap_content"
                android:layout_height="2dp"
                android:layout_marginTop="34dp"
                android:background="#FBFBFB" />

            <TextView
                android:id="@+id/time4_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:textSize="10sp" />

            <View
                android:id="@+id/subview4"
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_below="@id/time4_label"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="6dp"
                android:background="@drawable/timeline_bg_color" />

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

</androidx.cardview.widget.CardView>

Класс фрагмента

    public class PrescriptionFragment extends Fragment {

    Context thisContext;
    private RecyclerView myMedicineRecyclerView;
    private MyMedicinesAdapter myMedicinesAdapter;

    List<MyMedicine> myMedicineList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        System.out.println("Inside prescription onCreateView");
        thisContext = container.getContext();
        View view = inflater.inflate(R.layout.prescription_fragment, container, false);
        myMedicineRecyclerView = (RecyclerView) view.findViewById(R.id.myMedicines_RecyclerView);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(thisContext, RecyclerView.VERTICAL, false);
        myMedicineRecyclerView.setLayoutManager(layoutManager);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        final Button presHistoryButton = (Button) view.findViewById(R.id.prescriptionHistory_button);
        presHistoryButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(thisContext, "Prescription History Button Tapped", Toast.LENGTH_SHORT).show();
            }
        });
    }


    // This refreshList() method is getting called from my Fragments main class
    public void refreshList(List<TreatmentObject> data) {
        System.out.println("Inside of refreshList of Pres Fragment");
        System.out.println("Data size is" + data.size());
        System.out.println("Inside refreshList(data)" + data);
        myMedicineList = new ArrayList<>();

        for (int i = 0; i < data.size(); i++) {
            TreatmentObject treatmentObject = data.get(i);
            System.out.println(treatmentObject);
            int dosageImage;
            switch (treatmentObject.getFORM()) {
                case "Tablet":
                    dosageImage = R.drawable.ic_tablet_c;
                    break;
                case "Capsule":
                    dosageImage = R.drawable.ic_pills_c;
                    break;
                case "Bandage":
                    dosageImage = R.drawable.ic_bandage_c;
                    break;
                case "Concent...":
                    dosageImage = R.drawable.ic_medicine_c;
                    break;
                case "Drops":
                    dosageImage = R.drawable.ic_eyedrops_c;
                    break;
                case "Elixir":
                    dosageImage = R.drawable.ic_elixir_c;
                    break;
                case "Enema":
                    dosageImage = R.drawable.ic_enema_c;
                    break;
                case "Gel":
                    dosageImage = R.drawable.ic_gel_c;
                    break;
                case "Inhaler":
                    dosageImage = R.drawable.ic_inhaler_c;
                    break;
                case "Injection":
                    dosageImage = R.drawable.ic_syringe_c;
                    break;
                case "Kit":
                    dosageImage = R.drawable.ic_firsaidkit_c;
                    break;
                case "Spray":
                    dosageImage = R.drawable.ic_paintspray_c;
                    break;
                case "Syrup":
                    dosageImage = R.drawable.ic_syrup_c;
                    break;
                case "Tape":
                    dosageImage = R.drawable.ic_tape_c;
                    break;
                case "Tincture":
                    dosageImage = R.drawable.ic_tincture_c;
                    break;
                case "Wafer":
                    dosageImage = R.drawable.ic_wafer_c;
                    break;
                default:
                    dosageImage = R.drawable.ic_pills_c;
            }
            String startDate = null, endDate = null;
            if(treatmentObject.getStartDate() != null && treatmentObject.getStartDate() != "") {
                startDate = toISO8601UTCRepeat(fromISO8601UTCRepeat(treatmentObject.getStartDate()));
            }
            if(treatmentObject.getEndDate() != null && treatmentObject.getEndDate() != "") {
                endDate = toISO8601UTCRepeat(fromISO8601UTCRepeat(treatmentObject.getEndDate()));
            }
            String daysArray[] = new String[0];
            if(treatmentObject.getSCHEDULE() != null && treatmentObject.getSCHEDULE() != "") {
                if (treatmentObject.getSCHEDULE().equalsIgnoreCase("Daily")) {
                    daysArray = new String[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
                } else if (treatmentObject.getSCHEDULE().equalsIgnoreCase("Weekly")) {
                    if(treatmentObject.getDAYS() != null && treatmentObject.getDAYS() != "") {
                        String days = treatmentObject.getDAYS();
                        daysArray = days.split(", ");
                        System.out.println("Weekly Days Array is" + Arrays.toString(daysArray));
                    }
                }
            }
            String time1 = null, time2 = null, time3 = null, time4 = null;

            if (treatmentObject.getTIME1() != null && treatmentObject.getTIME1() != "" ) {
                time1 = toISO8601UTC(fromISO8601UTC(treatmentObject.getTIME1()));
            }
            if (treatmentObject.getTIME2() != null && treatmentObject.getTIME2() != "" ) {
                time2 = toISO8601UTC(fromISO8601UTC(treatmentObject.getTIME2()));
            }
            if (treatmentObject.getTIME3() != null && treatmentObject.getTIME3() != "" ) {
                time3 = toISO8601UTC(fromISO8601UTC(treatmentObject.getTIME3()));
            }
            if (treatmentObject.getTIME4() != null && treatmentObject.getTIME4() != "" ) {
                time4 = toISO8601UTC(fromISO8601UTC(treatmentObject.getTIME4()));
            }
            MyMedicine myMedicine = new MyMedicine(treatmentObject.getMedicineName(), dosageImage, startDate, endDate, daysArray, time1, time2, time3, time4, treatmentObject.getNOTE());
            myMedicineList.add(myMedicine);

            myMedicinesAdapter = new MyMedicinesAdapter(thisContext, myMedicineList);
            myMedicineRecyclerView.setAdapter(myMedicinesAdapter);
        }
    }

    public static String toISO8601UTC(Date date) {
        TimeZone tz = TimeZone.getTimeZone("UTC");
        DateFormat df = new SimpleDateFormat("hh:mma");
        df.setTimeZone(tz);
        return df.format(date);
    }

    public static Date fromISO8601UTC(String dateStr) {
        TimeZone tz = TimeZone.getTimeZone("UTC");
        System.out.println(tz);
        DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
        df.setTimeZone(tz);
        try {
            return df.parse(dateStr);
        } catch (ParseException e) {
            System.out.println("Inside catch exception");
            e.printStackTrace();
        }
        return null;
    }

    public static String toISO8601UTCRepeat(Date date) {
        TimeZone tz = TimeZone.getTimeZone("UTC");
        DateFormat df = new SimpleDateFormat("MMM dd, yyyy");
        df.setTimeZone(tz);
        return df.format(date);
    }

    public static Date fromISO8601UTCRepeat(String dateStr) {
        TimeZone tz = TimeZone.getTimeZone("UTC");
        System.out.println(tz);
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        df.setTimeZone(tz);
        try {
            return df.parse(dateStr);
        } catch (ParseException e) {
            System.out.println("Inside catch exception");
            e.printStackTrace();
        }
        return null;
    }
}
...