Fragmentstateadapter в viewpager2 не показывает фрагмент в компоненте архитектуры навигации

Я использую компонент архитектуры навигации - One Activity Many Fragment Style. В ProfileEditHolderFragment я хочу показать список фрагментов с возможностью замены, используя последние версии ViewPager2 и FragmentStateAdapter. Я реализовал это, как показано ниже.

ProfileEditHolderFragment.kt

class ProfileEditHolderFragment : BaseFragment() {

    override fun getLayoutResId() = R.layout.fragment_profile_edit_holder

    override fun initWidget() {
        profile_state_progress_bar.setStateDescriptionData(arrayOf("Tuition", "Education", "Personal", "Credential", "Quiz"))

        val listOfFragment = listOf<Fragment>(TuitionInfoFragment(), EditEducationFragment())
        profile_edit_view_pager.adapter = activity?.let {
            TutorProfileEditAdapter(it, listOfFragment)
        }
    }

}

fragment_profile_edit_holder.xml

<androidx.core.widget.NestedScrollView
    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=".ui.fragment.tutorPanel.profileEdit.ProfileEditHolderFragment">

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

        <another view>

        <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/profile_edit_view_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="@dimen/_20sdp"
                android:orientation="horizontal"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/profile_state_progress_bar"
                app:layout_constraintBottom_toBottomOf="parent"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

TutorProfileEditAdapter.kt

class TutorProfileEditAdapter(
    activity: FragmentActivity,
    private val fragmentList: List<Fragment>
): FragmentStateAdapter(activity) {

    override fun getItemCount() = fragmentList.size

    override fun createFragment(position: Int) = fragmentList[position]

}

Но проблема в том, что фрагменты не отображаются в держателе ViewPager2.


person Aminul Haque Aome    schedule 18.11.2019    source источник
comment
Я думаю, вы должны добавить скриншот сценария навигации, который вы пытаетесь показать.. (1) в первом макете xml попробуйте изменить ширину/высоту с «match_parent» на «0dp» (2) ... youtube.com/watch?v=KwihiADN-0k   -  person Marlon López    schedule 13.04.2020


Ответы (1)


Попробуйте использовать childFragmentManager вместо активности

person Madina Saidova    schedule 18.11.2019