I'm new to java and unfortunately my brain is fixed in javascript land... This isn't good.
Anyways, I'm trying to just make a simple menu open and close using java. I have this script:
public class StartPage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_page);
//Handlers
RelativeLayout menuContainer = (RelativeLayout) findViewById(R.id.MenuContainer);
ImageView menuButton = (ImageView) findViewById(R.id.temp_menu);
Boolean menuOpen = false;
//Make sure the menu is not displaying
menuContainer.setVisibility(View.GONE);
menuButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!menuOpen) {
boolean menuOpen = true;
RelativeLayout menuContainer = (RelativeLayout) findViewById(R.id.MenuContainer);
menuContainer.setVisibility(View.VISIBLE);
} else {
boolean menuOpen = false;
RelativeLayout menuContainer = (RelativeLayout) findViewById(R.id.MenuContainer);
menuContainer.setVisibility(View.GONE);
}
}
});
}
}
So, I make the variable menuOpen false right off the bat, but I want to use and manipulate that variable in an if statement.
I get an error in the if statement that says I need to make the variable final, so I make it final, but then I'm not able to change that variable later on.
This is my javascript brain thinking, so I'm not sure if there's a better way to do this in Java. Any help?
if (menuOpen == false), you can just useif (!menuOpen)if(!menuOpen), I was playing around a lot with it just as trial and errormenuOpenas member variable of the classStartPage. Then access it usingStartPage .this.menuOpeninside anonymous class.