Variable Problem


#1

Hi there … I was trying to make a navigation drawer but I failed as I cant inherit the variable “toggle” and its Properties in the last function. Is there a way to declare my variable “toggle” rather than the line I declare it in or any method to help me inherit the variable properties ?


#2

toggle and drawer are local variables in your onCreate method and are only visible inside of that method and actually cease to exist when that method is exited. You probably want to make them properties of the class using lateinit as in:

private lateinit var drawer: DrawerLayout
private lateinit var toggle: ActionBarDrawerToggle

and you then initialize them in onCreate (just remove var from those lines)


#3

You are so smart sir , Thank you for your help . It Works .