Я пытаюсь сделать RecyclerView во фрагменте, я создал переработчик-адаптер с Groupie Library, он проще для меня и работает очень хорошо.Таким образом, я получил эту ошибку: "recyclerview_list не должен быть нулевым".
Мои файлы:
RecyclerView: recycler_list:
<?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"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_list"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Fragment: ParksFragment.kt
class ParksFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_parks, container, false)
recyclerview_list.layoutManager = LinearLayoutManager(context)
val adapter = GroupAdapter<ViewHolder>()
adapter.add(ParkListFragment())
adapter.add(ParkListFragment())
adapter.add(ParkListFragment())
recyclerview_list.adapter = adapter
}
}
class ParkListFragment:Item<ViewHolder>(){
override fun bind(viewHolder: ViewHolder, position: Int) {
Log.d("Myfragment", "Recyclerview is working")
}
override fun getLayout(): Int {
return R.layout.fragment_parks
}
}
frag_parks:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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=".tourism.ParksFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Park Name"
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="@+id/textview_parks_fragment"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:text="Place Direction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textview_parks_fragment"
app:layout_constraintEnd_toEndOf="@+id/textview_parks_fragment"
app:layout_constraintStart_toStartOf="@+id/textview_parks_fragment"/>
</android.support.constraint.ConstraintLayout>
Я попробовал некоторые решения, которые нашел здесь, но не могу понять, как это сделать.