Welcome Guest [Log In] [Register]
Welcome to Life In Java. We hope you enjoy your visit.


You're currently viewing our forum as a guest. We hope that you will join us so you can help out with any questions, post your final projects for publishing, or even write a tutorial!

Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Having the same menu on more than one Activity
Topic Started: Oct 18 2010, 03:01 PM (77 Views)
Samuel
Member Avatar



Create a class like so:
Code:
 

public class BaseActivity extends Activity // this is the class that includes the menu
{
@Override
public void onCreateOptionsMenu()
{
//Construct your options menu here
}

@Override
public void onOptionsItemSelected(...)
{
//handle your options menu item clicks here
}
}


Then, anytime you have an activity that must include this option menu, just define it as so:

Code:
 

public class SubActivity extends BaseActivity // this is any other class that you want the menu to be in. Extend the activity that has the menu in it instead of Activity, because the BaseActivity is already extending Activity
{
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
//and so on
}


}

Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Official Tutorials · Next Topic »
Add Reply

Black Water created by tiptopolive of IDS