stracqan
asked on
How do I subclass(?) Android Menu?
Hello,
This is more of a Java formatting question, but I was wondering how do I put my Menu Option Handler in another class and then refer to it elsewhere?
In other words, what do I need to pass to my subclass (is that even the right word to use?) and then how do I call that class in another class / activity? Basically, this is a snippet of code that I would like to re-use in many classes / Activities, and if I modify it I would like it to change everywhere.
Attached is the code I would like to subclass(again, not sure if that is the right word).
Thanks!!!!
This is more of a Java formatting question, but I was wondering how do I put my Menu Option Handler in another class and then refer to it elsewhere?
In other words, what do I need to pass to my subclass (is that even the right word to use?) and then how do I call that class in another class / activity? Basically, this is a snippet of code that I would like to re-use in many classes / Activities, and if I modify it I would like it to change everywhere.
Attached is the code I would like to subclass(again, not sure if that is the right word).
Thanks!!!!
//handle menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.loading_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.option1:
//do something in here that is relevant to
//the class that was calling it. i.e.
//stopping a video from playing etc.
return true;
default:
return super.onOptionsItemSelected(item);
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
ASKER