[Solved] Building a menu in Android [closed]


This is a sample code I made. all of them are buttons in xml

public class MenuActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
}


@Override
// My menu inflater
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.menu, menu);

return (super.onCreateOptionsMenu(menu));
}

// code for the actions that it will do.
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.test2:
    test2();
    return true;
case R.id.test1:
    test1();
    return true;
default:
    return super.onOptionsItemSelected(item);
}
}

 public void test1() {
// TODO Auto-generated method stub
Toast test = Toast.makeText(this, "This is a test", Toast.LENGTH_LONG);
test.show();
 }

 public void test2() {
// TODO Auto-generated method stub
Toast test = Toast.makeText(this, "This is a test", Toast.LENGTH_LONG);
test.show();
  //Add how ever many you want. 
 }
}

solved Building a menu in Android [closed]