0

如何从 MvpActivity 访问 MvpFragment。

片段,使用当前代码 -

class Fragment1: MvpFragment<IView, Presenter>(){
    override fun createPresenter(): Presenter {
        return Presenter(getActivity().getApplicationContext())
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater!!.inflate(R.layout.activity_main, container, false)
    }
}

活动是——

class MainActivity : MvpActivity<IView, Presenter>(), IView {
    override fun createPresenter(): Presenter {
        return Presenter(getApplicationContext())
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun create_fragment(view: View){
        var frgmnt = getFragmentManager().beginTransaction()
        frgmnt.replace(R.id.containerZ, Fragment1())
    }
}
4

1 回答 1

0

我认为 mosby 使用支持片段,所以试试这个

var frgmnt = getSupportFragmentManager().beginTransaction()
于 2017-12-05T18:09:00.337 回答