如何调用mvp模式中活动的片段



问题是,我无法从DashboardActivity移动到BookingFragment。

//BookingFragment
companion object {
fun start(): BookingFragment {
val fragment = BookingFragment()
return fragment


}



//Calling back this function in activity inorder to move on that fragment
fun getBookingView() {
BookingFragment.start()
}

//Fragment activity
private lateinit var binding: FragmentBookingBinding
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
super.onCreate(savedInstanceState)
val mvpKotlinApplication = AppApplication()
DaggerBookingComponent.builder()
.appComponent(mvpKotlinApplication.get(requireActivity()).appComponent)
.bookingModule(BookingModule(activity as AppCompatActivity))
.build()
.inject(this)

//装订binding=FragmentBookingBinding.flupt(布局充气器(val view=binding.rootbookingView.start(绑定(bookingPresenter.onCreateView((返回视图}
//DashboardPresenter::
private fun onClick() {
dashboardView.getBookingObserable().doOnNext { dashboardModel.getBookingView() }
.subscribe()
}

您可能需要在活动中创建一个片段容器视图,然后继续进行片段事务。请参阅文档-https://developer.android.com/guide/fragments/create

基本上你会有这样的东西:

<!-- res/layout/example_activity.xml -->
<androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
fun getBookingView() {
supportFragmentManager.commit {
add(BookingFragment.start())
}
}

相关内容

  • 没有找到相关文章