Надуйте RecyclerView, который вложен в ContraintLayout

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

Проблема в том, что макет больше не является просто компонентом RecyclerView, я заключил его в ConstraintLayout и добавил FloatingActionButton.

Как я могу надуть эту конкретную часть представления или как лучше всего решить эту проблему, когда адаптер никогда не инициализируется из-за кода (view instanceof RecyclerView).

View view = inflater.inflate(R.layout.fragment_search_list, container, false);

Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;

if (view instanceof RecyclerView) {
    recyclerView.setLayoutManager(new LinearLayoutManager(context));

    mySearchRecyclerViewAdapter = new MySearchRecyclerViewAdapter(gameList, mListener);
    recyclerView.setAdapter(mySearchRecyclerViewAdapter);
}

Макет:

<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width = "match_parent"
    android:layout_height = "match_parent"
    tools:context = "com.scuvanov.weplay.fragment.SearchFragment">

    <android.support.v7.widget.RecyclerView
        android:id = "@+id/list"
        android:name = "com.scuvanov.weplay.fragment.SearchFragment"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:visibility = "visible"
        app:layoutManager = "LinearLayoutManager"
        tools:listitem = "@layout/fragment_search">

    </android.support.v7.widget.RecyclerView>

    <android.support.design.widget.FloatingActionButton
        android:id = "@+id/fabSearch"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginBottom = "15dp"
        android:layout_marginEnd = "15dp"
        android:clickable = "true"
        android:focusable = "true"
        android:src = "@drawable/ic_action_search"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent" />

</android.support.constraint.ConstraintLayout>
recyclerView = view.findViewById(R.id.list)?
Yupi 21.05.2018 16:29

Спасибо, ответ смотрел мне прямо в лицо.

Coova 22.05.2018 03:35
0
2
67
0

Другие вопросы по теме