RecyclerView исчезает при изменении макета - PullRequest
0 голосов
/ 18 мая 2019

У меня есть фрагмент с обзором переработчика, он работает нормально и только с обзором переработчика.

Оригинальный XML, который работает :

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/list"
    android:name="pt.lusofona.helpnow.HospitalFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="LinearLayoutManager"
    tools:context=".HospitalFragment"
    tools:listitem="@layout/fragment_hospital" />

Я пытался добавить FAB, поэтому я добавил Constrained Layout, и я понял, что если я добавлю что-нибудь на экран, просмотрщик перестанет показывать элементы.

С кодом ниже он перестанет отображать элементы (пусто)фрагмент):

<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.v7.widget.RecyclerView xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/list"
    android:name="pt.lusofona.helpnow.HospitalFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutManager="LinearLayoutManager"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:context=".HospitalFragment"
    tools:listitem="@layout/fragment_hospital" />

</android.support.constraint.ConstraintLayout>

Я проверил похожие ответы, но ничего не помогло.

Вот так я установил адаптер на HospitalFragment

    if (view instanceof RecyclerView) {
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;            
        adapter = new MyHospitalRecyclerViewAdapter(DummyContent.ITEMS, mListener);
        recyclerView.setAdapter(adapter);
    }
    return view;

1 Ответ

1 голос
/ 18 мая 2019

После моего комментария приведен фрагмент кода:

RecyclerView recyclerview = view.findViewById(R.id.list);
if (recyclerview != null) {
    Context context = view.getContext();
    adapter = new MyHospitalRecyclerViewAdapter(DummyContent.ITEMS, mListener);
    recyclerview.setAdapter(adapter);
}
return view;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...