I\'m trying to create a simple menu with one button that will call a method to clear the array. I don\'t want to use xml because all I need is one button.
Something like
Something like this might work:
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem item = menu.add ("Clear Array");
item.setOnMenuItemClickListener (new OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick (MenuItem item){
clearArray();
return true;
}
});
return true;
}
Menu
gives us a handy method, add(), which allows you to add a MenuItem. So we make one.
Then we assign an OnMenuItemClickListener to the MenuItem
and override its onMenuItemClick() to do what we want it to do.