Sam
Sam

Reputation: 360

Extending Menu Items on all screens for android .

I am using actionbarsherlock. Using the following code I have created a menu for the home screen

@Override
public boolean onCreateOptionsMenu(Menu menu) {
   MenuInflater inflater = getSupportMenuInflater();
   inflater.inflate(R.layout.menu, menu);
   return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.about:
            Intent i = new Intent(this, AboutApp.class); // Start About.java Activity
            startActivity(i);
            return true;
        case R.id.feedback:
            Intent j = new Intent(this, SendFeedback.class); 
            startActivity(j);
            return true;
       default:
            return super.onOptionsItemSelected(item);
    }
}

How do I extend this menu to all the screens across the entire app ?

Upvotes: 0

Views: 276

Answers (2)

Blackbelt
Blackbelt

Reputation: 157457

Create a BaseClass that extends Activity (or FragmentActivity) and let other sublcass it.

OtherClass extends BaseClass

Since BaseClass extends SherlockFragmentActivity, OtherClass will extends it too.

Upvotes: 1

pshirishreddy
pshirishreddy

Reputation: 746

Create a BaseActivity including this functionality and make rest of your activities extend this activity.

Upvotes: 1

Related Questions