Link to home
Start Free TrialLog in
Avatar of stracqan
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!!!!
//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);
        }
        
    }

Open in new window

SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stracqan
stracqan

ASKER

Would you mind posting an example please?
ASKER CERTIFIED SOLUTION
Avatar of Dejan Pažin
Dejan Pažin
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!