Previously, I used ImageButtons to navigate through Activities. Now I am going to make a standard Left Navigation Drawer. But the Application need to Extend Activity where as the Default Navigation includes Extend NavigationDrawerActivity. How to Handle this?
I need something like:
public class Main extends Activity {
//Bla Bla Bla
}
And the Drawer Sample App already has this piece of cake:
public class Main extends ActionBarActivity implements
NavigationDrawerFragment.NavigationDrawerCallbacks {
private NavigationDrawerFragment mNavigationDrawerFragment;
//This and that
}
The ActionBarActivity already extends the Activity class so if your activity extends ActionBarActivity nothing you have will break.
(You will need to have support library v7 in order for you to be able to extend ActionBarActivity)
Related
My main activity extends AppCompatActivity where I create and inflate my menu. I also want my main activity to contain a map fragment. This requires that my main activity extends FragmentActivity, but I cannot extend from two super classes. How am I supposed to add a map fragment to my main activity?
AppCompatActivity extends FragmentActivity, so you get all of the functionality in FragmentActivity by extending AppCompatActivity.
Well, AppCompatActivity already extends FragmentActivity, so there should be no problem.
My drawer is created by android studio automatically and I realized that its structure is not as it was like when I created handly. API23 suggests developers to use assembled layout files. How can I use the same drawer in different activities with API23?
create xml of only drawer component and include it in every activity layout.
After that to write java code of drawer create CommonActivity class which extends activity and write here drawer now user CommonActivity rather than extending Activity class in every activity class
like
public class CommonActivity extends Activity
{
oncreate
{
//drawer code
}
}
public class YourActivity extends CommonActivity
{
//No need to write drawer code here again
}
Toolbar mainly should used with ActionBarActivity
if I want to use it by Extends Activity it gives an error
when I call
setSupportActionBar(toolbar);
I main Above I don,t want to use ActionBarActivity
Any help here , And what About Another kind Of Activities
Like FragmentActivity or Others .
Example to support FragmentActivity
ActionBarActivity activity = (ActionBarActivity) getActivity();
activity.setSupportActionBar(toolbar);
If you're extending Activity just use setActionBar(). setSupportActionBar is for when your're using ActionBarActivity from the support library
You have done little mistake .. you had to extend
ActionBarActivity
not only
Activity
class ..when you do error will be removed.
I have two different classes. My main activity class and a separate menu.class. I want to be able to get the menu class to load from the mainactivity.class. The menu button does not work on my device or emulator when the mainActivity class is running. I am not sure how to call the menu.class from the mainActivity. I do not want to put the menu java code in the mainActivity.
I am asking for the way to add a snip of code to load a menu activity from one class to another, not to fix my code. I can not find any examples online to show how to load a menu class that is not also written in your main activity class.
public class lifeMenu extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.life_menu);
}
That is a snip of my menu activity. My main activity is called MainActivity
You can make your MainActivity extend your MenuActvity that entends Activity. Hard to know since you did not provide a snip of your menu class.
In the documentar from SlidingMenu is written down:
Go into the SlidingActivities that you plan on using make them extend Sherlock__Activity instead of __Activity.
The setup should be ok, I followed the guide, but if I try to extend my Activity with for example: SlidingSherlockFragmentActivity or SherlockSlidingFragmentActivity doesn't work.
If I extend my Activity with SherlockFragmentActivity I can't get the SlidingMenu with getSlidingMenu() or call setBehindContentView.
Nevermind, go into the SlidingMenu library and extend the Activity by SherlockFragmentActivity instead of FragmentActivity
Go to activities of library SlidingMenu and extends all activities to SherlockActivities corresponding, after go to your app and extends all activities to SlidingActivity corresponding.
Example: SlidingMenu:
SlidingActivity extends SherlockActivity
SlidingMapActivity extends SherlockMapActivity
Example: MyClass
MyClass extends SlidingActivity
MyClass extends SlidingMapActivity