qingmei2 / MVVM-Architecture

The practice of MVVM + Jetpack architecture in Android.
1.83k stars 282 forks source link

BaseFragment貌似有点问题 #21

Closed 7-cat closed 5 years ago

7-cat commented 5 years ago

MVVMRhine/mvvm_rhine/src/main/java/com/qingmei2/rhine/base/view/fragment/BaseFragment.kt

abstract class BaseFragment : InjectionFragment() {

private var mRootView: View? = null

abstract val layoutId: Int

override fun onCreateView(inflater: LayoutInflater,
                          container: ViewGroup?,
                          savedInstanceState: Bundle?): View {

//这里有点问题,改成mRootView = inflater.inflate(layoutId, container, false)就好了,具体原因未知 mRootView = LayoutInflater.from(context).inflate(layoutId, container, false) return mRootView!! }

override fun onDestroyView() {
    super.onDestroyView()
    mRootView = null
}

}

qingmei2 commented 5 years ago

@7-cat

根据你的描述,我不是很清楚,请问遇到了什么问题吗?

7-cat commented 5 years ago

抱歉,本来打算把具体的报错贴出来的,可是今天又不能重现这个问题了。。估计是fragment嵌套或者什么问题引起的。准备移步到MVI-Rhine,感谢你开源这么好的代码,学到了很多。

qingmei2 commented 5 years ago

@7-cat

你没有错,直接使用型参中的inflater才是正确的使用方式。

从原理上讲,这两种方式获取的LayoutInflater对象是不一样的,抽空我研究一下源码,仔细看看差异性在哪里。