не отображаются фрагменты в tablayout+viewpager2
значит адаптер такой:
class pageradapter(fragment: FragmentActivity,private var list:List<Fragment>) : FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 2
override fun createFragment(position: Int): Fragment {
return list[position]
}
}
инициализация такая:
var tab = view.findViewById<TabLayout>(R.id.tab_layout)
tab.addTab(tab.newTab().setText("заметка"))
var pager = view.findViewById<ViewPager2>(R.id.pager)
pager.adapter = pageradapter(requireActivity(), listOf(notesrecyclerview(),list0()))
var tabNames = arrayListOf("Заметки","Списки")
TabLayoutMediator(tab, pager) { tab, position ->
tab.text = tabNames[position]
}.attach()
сами фрагменты идентичны(но это разные файлы, идентичность в разметке), поэтому добавил только одну разметку:
<?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=".notesrecyclerview">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerviewitem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:verticalScrollbarPosition="defaultPosition"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout"
tools:listitem="@layout/recyclerviewitem"></androidx.recyclerview.widget.RecyclerView>
</FrameLayout>
и котлин файл фрагмента на всякий:
class notesrecyclerview : Fragment() {
private val binding by viewBinding(FragmentNotesrecyclerviewBinding::bind)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.recyclerviewitem.adapter = recyclerviewclass()
binding.recyclerviewitem.layoutManager = LinearLayoutManager(requireActivity())
}}
таблайоут он выводит, но сами фрагменты не отображает , типа вкладки есть, а они ничего не переключают, просто белый экран