如何在 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 binding = FragmentBookingBinding.inflate(layoutInflater) val view = binding.root bookingView.start(binding) bookingPresenter.onCreateView() return view }
 //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())
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在 MVP 中恢复模型状态?

如何在活动中调用片段类?

如何在活动中调用片段方法

如何从活动中调用片段

在MVP模式中,如何访问Presenter中的指定视图组件?

如何使用 Dagger2 和 MVP 模式调用模型文件中的演示者方法

如何在MVP模式下在EditText中保持脏状态?

如何从片段中调用活动方法?

如何从活动中调用片段函数?

如何从父活动调用片段中的方法?

android MVP - 如何从模型中调用网络层?

如何在Kotlin-MVP的Adapter类中的button.setOnClickListener中显示片段对话框?

如何使用MVP在OpenGL中绘制椭圆

如何从 mvp 中的另一个片段转到片段

如何使用Android的MVP模式控制ListView

MVP模式WinForms:如何正确更新UI?

GWT中的MVP模式:如何在Presenter中初始化Model / View并处理服务器请求?

如何从我的活动中调用片段中的方法?

MVP-如何通过片段夸大菜单中的网络通话?

如何在Android中的MVP架构中的两个演示者之间共享数据?

如何在活动中访问片段的按钮

如何在片段中隐藏活动视图

如何在活动中动态添加片段?

尝试使用Dagger 2实现MVP-如何在提供的演示者中获取对Activity的引用

如何在MVP中的演示者和数据服务之间传输数据

在MVP结构中,哪个类负责保存列表项以及如何在此通知数据更改

如何在文本框中显示所选行MVP C#

如何从Android中的非活动类调用片段

Android如何从我的主要活动中调用片段