Linked Questions

Popular Questions

Well I have created a new Android Project with kotlin and I have chosed the option Bottom Navigation Activity and I don't know what is the best way on terms of performance and to avoid future problems to swipe between Fragments depending on the OnNavigationItemSelectedListener

Generated pice of code in our Mainactivity:

private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
    when (item.itemId) {
        R.id.navigation_home -> {
            message.setText(R.string.title_home)
            [email protected] true
        }
        R.id.navigation_dashboard -> {
            message.setText(R.string.title_dashboard)
            [email protected] true
        }
        R.id.navigation_notifications -> {
            message.setText(R.string.title_notifications)
            [email protected] true
        }
    }
    false
}

The idea would be get something like:

R.id.navigation_home -> {
    switchFragment(MyFragment.newInstance())
    [email protected] true
}

But I'm not sure how to implement this in a proper way.

I found a very an old('13) similar question but focus on java and not kotlin and should be a different way. Java question

Related Questions