底部导航视图双击

pie*_*pie 2 android bottomnavigationview

创建片段时,我从网络下载数据。单击已激活的菜单项时如何避免重新加载?转换与导航组件一起使用。我知道我需要听取媒体的意见,但我还没有弄清楚实施方式。

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

        val navController = findNavController(R.id.fragmentContainerView)

        val appBarConfiguration = AppBarConfiguration(setOf(R.id.ruleListFragment))
        setupActionBarWithNavController(navController, appBarConfiguration)

        bottomNavigatinView.setupWithNavController(navController)
        
        bottomNavigatinView.setOnNavigationItemSelectedListener { 
            //TODO
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Sam*_*ari 5

如果您只想防止在客户端按下已经活动的菜单项时重新创建片段,这是您需要的唯一代码:

bottomNavigatinView.setOnNavigationItemReselectedListener { 
    // Empty Block -> Do not write any code here
}

Run Code Online (Sandbox Code Playgroud)