• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Can anybody explain this Java code?

Ali_Delta

Lurker
Hi, I am new to android programming.
I don't know java programming.
Can anyone explain this code for me?


public void onClick(View v) {
switch (v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
}
}

Sorry for English:D
 
Its a generic button onClick event handler. The switch is there to allow you to test which button was clicked. It has one single case which tests for the about_button. if it was pressed then it creates a new intent (looks like it may be an About box or something) and starts it. In summary it shows an about box if the user presses the about button.
 
What about this code?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
 
This is an event handler that is called to initialise the options menu for the activity that it is defined in and the inflate method creates the menu from the R.menu.menu resource; The MenuInflator instantiates menus from the XML that define them
 
Back
Top Bottom