我有一个带有2个片段的活动(让我们称之为A和B),每个片段都有一个回收者视图。
我通过
添加片段val fragment = supportFragmentManager.findFragmentById(R.id.activity_home_fragment)
this.supportFragmentManager
.beginTransaction()
.remove(fragment)
.add(R.id.activity_home_fragment, newFragment)
.addToBackStack(null)
.commit()
当我进行正向流动(A - > B)时,所有的Recyclerviews都正常加载。但是,当我回到第一个片段(B - > A)时,使用后退按钮,回收站视图无法加载。
我正在使用kotterknife来注入我的观点
val recyclerBuildList by bindView<RecyclerView>(R.id.fragment_build_list_recycler)
以下是我用来创建适配器的代码:
override fun onResume() {
super.onResume()
val build1 = Build()
build1.id = 3
build1.name = "Build 1"
val build2 = Build()
build2.id = 4
build2.name = "Build 2"
val list = arrayListOf(build1, build2)
setupBuildList(list)
}
private fun setupBuildList(builds: List<Build>) {
recyclerBuildList.setHasFixedSize(true)
val adapter = BuildListAdapter(activity, eventBus)
recyclerBuildList.layoutManager = LinearLayoutManager(activity)
adapter.builds = builds
recyclerBuildList.adapter = adapter
recyclerBuildList.requestLayout()
}
PS:我在我的项目中使用Kotlin
我检查了层次结构视图,而RecyclerView
中没有任何内容