Я впервые использую NavigationView, и у меня возникла проблема.
Когда я нажимаю на элемент в NavigationView, он переходит в начальную позицию без отображения тоста.
Это мой код:
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navigationView = findViewById<NavigationView>(R.id.navigationView)
navigationView.setNavigationItemSelectedListener(this)
phoneBTT.setOnClickListener {
Toast.makeText(this, "Phone BTT is clicked", Toast.LENGTH_LONG).show()
}
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when(item.itemId)
{
R.id.galleryBTT -> {
Toast.makeText(this, "Gallery BTT is clicked", Toast.LENGTH_LONG).show()
}
R.id.exitBTT -> {
Toast.makeText(this, "Exit BTT is clicked", Toast.LENGTH_LONG).show()
}
R.id.alarmBTT -> {
Toast.makeText(this, "Alarm BTT is clicked", Toast.LENGTH_LONG).show()
}
R.id.creditCardBTT -> {
Toast.makeText(this, "CreditCard BTT is clicked", Toast.LENGTH_LONG).show()
}
}
return true
}