【发布时间】:2020-05-07 12:01:51
【问题描述】:
我有一个观察者,当它被称为更改片段时。
问题是当我返回时立即调用观察者并且我的应用程序崩溃了
java.lang.IllegalArgumentException:导航目的地 com.superapps.ricardo.tablepro:id/action_searchFragment_to_yourGameList2 此 NavController 未知。
我不明白为什么要调用它。
这是唯一改变列表的方法
override fun onSuccess(gamePair: Pair<Int, List<BggGame>>) {
CoroutineScope(Main).launch{
//goToList(gamePair.second, binding.input.text.toString())
viewModel.setGameList(gamePair.second)
}
}
这是视图模型创建和更改片段代码
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(SearchViewModel::class.java)
viewModel.gameList.observe(viewLifecycleOwner, Observer {
goToList(it, binding.input.text.toString())
})
}
private fun goToList(games: List<BggGame>, user: String) {
val action = SearchFragmentDirections.actionSearchFragmentToYourGameList2(user)
val gameList = GameList()
gameList.gameList = games
action.gameList = gameList
try {
Navigation.findNavController(view!!).navigate(action)
viewModel.gameList.removeObservers(viewLifecycleOwner)
} catch (e: Exception){
Log.e("a0,","a..", e)
}
progressDialog.dismiss()
}
【问题讨论】:
-
请分享您的 viewModel 代码!!