-2

This is the code in onNavigationItemSelected

  R.id.nav_subscribed -> {
        if (prefs.getLong("userid", 0L) == 0L) {
            when (currentGal) {
                "top" -> {
                    // navView.setCheckedItem(R.id.nav_top)
                    // navView.menu.getItem(R.id.nav_top).isChecked = true
                }
            }

            val i = Intent(this, Login::class.java)
            this.startActivity(i)
        } else {
            if(currentGal != "subscriptions"){
                getMemes("subscriptions", 0)
            }
        }
    }

I try to prevent nav_subscribed to be checked when the user isn't logged in and check/keep checked nav_top

navView.setCheckedItem(R.id.nav_top)

isn't working and

navView.menu.getItem(R.id.nav_top).isChecked = true

crashed the app. So how to do this? Btw android is awful broken garbage software

Eduard Unruh
  • 985
  • 1
  • 14
  • 35

1 Answers1

0
     navigationView?.setOnNavigationItemSelectedListener {
    
                when (it.itemId) {
                    R.id.nav_subscribed -> { 
  //  if you don't want an item to be selected return false
         return@setOnNavigationItemSelectedListener false
                    }
                    R.id.nav_top -> {
                       
                    }
                
                 
                }
//return true to select the other items
                true
            }
huda Olayan
  • 143
  • 1
  • 13