如何解决如何通过单击菜单项使 recyclerView 滚动到顶部位置?
我需要这样,如果单击菜单项“打开所有单词”(如下所示),则视图会滚动到顶部位置。 如何从 onOptionItemSelected() 方法执行此操作以及在那里输入什么内容?
感谢任何帮助。
@AndroidEntryPoint
class VocabularyFragment : Fragment(R.layout.recycler_layout),VocabularyAdapter.OnVocItemClickListener {
private val viewModel: VocabularyViewModel by viewModels()
private lateinit var searchView: SearchView
override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
super.onViewCreated(view,savedInstanceState)
val binding = RecyclerLayoutBinding.bind(view)
val vocabularyAdapter = VocabularyAdapter(this)
binding.apply {
recyclerView.apply {
adapter = vocabularyAdapter
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
itemAnimator = null // ХЗ НАДО ЛИ
}
}
viewModel.words.observe(viewLifecycleOwner) {
vocabularyAdapter.submitList(it)
}
setHasOptionsMenu(true)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_choose_all_categories -> {
viewModel.onChooseCategoryClick(0)
// HERE I NEED TO call the recycler view and make it scroll to the top to the 1st position
true
}
//other items ...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。