ohadinho
ohadinho

Reputation: 7144

Android UI design pattern - Options Menu

I want to use my options menu on every activity that I have on my project.

So I've created an OptionsMenuActivity which inherits from Activity.

Each activity I've created inherit from it.

The problem is when creating MyPreferenceActivity which inherits from PreferenceActivity, I cannot use it.

What is the best way doing it ?

Upvotes: 1

Views: 250

Answers (1)

melston
melston

Reputation: 2352

If all you are looking to do is find a place to put the onCreateOptionsMenu() and onOptionsItemSelected() methods you can create a separate class with those two methods, make an instance of that class a member of all your activities, and make these two methods 'pass through' methods in your activities, deferring to the member object that now handles the requests.

Your new class does not have to inherit from Activity to do its job. However, the onOptionsItemSelected() method may have to return some indication as to whether it actually handled the request or not so your Activity's method can call 'super.onOptionsItemSelected()' as necessary.

Upvotes: 1

Related Questions