How to use Sliding Activity and Fragment Activity in a single class? - android

So I have an app where in one of the screens there is a sliding menu (jfeinstein's) and I also want to implement a tab view using fragments. For this I need to extend the FragmentActivity but I have already extended SlidingActivity and I can't extend more than one class. Is there a way to work around this so that I have both a sliding menu and a tab menu in the same class?

Instead of extending the Activity you can integrate it, as listed in point 1 of the usage guidelines.
"You can wrap your Activities in a SlidingMenu by constructing it programmatically (new SlidingMenu(Context context)) and then calling SlidingMenu.attachToActivity(Activity activity, SlidingMenu.SLIDING_WINDOW | SlidingMenu.SLIDING_CONTENT). SLIDING_WINDOW will include the Title/ActionBar in the content section of the SlidingMenu, while SLIDING_CONTENT does not. You can check it out in the example app AttachExample Activity."
- GitHub page, usage section
The SlidingMenu was written for a time when the navigation drawer pattern didn't have a native implementation in the SDK. There is one now: you can use the NavigationDrawer which is included in the v4 Support Library. There is a guide for that here on the developer pages.

Related

NavigationDrawer on right managed by fragment or not?

I use this library:
https://github.com/mikepenz/MaterialDrawer
I would like to have a right NavigationDrawer with a ListView (or a lot of items) inside and I get items from DB inside the Fragment and when user click on items on the NavigationDrawer I get data from another DB and show it on Fragment.
and I have a questions:
is possible to create a right Drawer inside a Fragment? or is better to create a new right Drawer in MainActivity and change the navigation item inside the Fragment?
Just use brand new Navigation View from recenlty released Android Design Support Library by Google.
Here are links for you:
official documentation, always a good read: https://developer.android.com/reference/android/support/design/widget/NavigationView.html
nicely written blog post about Navigation View: http://antonioleiva.com/navigation-view/
and last but not least, sample app using new Android Design Library: https://github.com/antoniolg/MaterializeYourApp
To have Navigation View on the right, just set android:layout_gravity to end.
As from design point of view, you should always use left sided Navigation Drawer, it is possible to make it right sided, but its recommended to leave it at the left side.
Another thing is that you do not need to use 3rd party navigation drawer libraries.Since there is a Design library by google, which supports the material design navigation view.
Here is a link for the library:
https://developer.android.com/tools/support-library/features.html
And here is another useful link:
https://guides.codepath.com/android/Design-Support-Library
Here is the link for the Navigation Drawer: https://guides.codepath.com/android/Fragment-Navigation-Drawer
As for your question the appropriate way is to create the drawer always in the main activity onCreate() method.

Navigation Drawer + Sliding Tabs inside fragment Android

I'm trying to get a NavigationDrawer working with sliding tabs inside a fragment (just like google play music or the google i/o app). In all my reasearch I found that you can't use Action bar tabs + Navigation Drawer together because the Navigation drawer will look like in the back of the tabs (I notice that). Can anyone help me telling me how to get that done without use an external library such ActionBarSherlock or TabHost (according to the documentation is recommended the use of actionbar)?
Yes, you're right. It won't be possible using ActionBar tabs as the navigation drawer won't overlap them. I recently implemented a library called ViewPagerAddons which has a custom view called SlidingTabLayoutColors imitating the behavior seen in Google Play/Music.
But as you said you don't want to use any libraries, you can still have a look at the source code. Here's the link with instructions: https://bitbucket.org/enthusiast94/viewpageraddons

Viewpager inside a fragment is it possible

I want to know whether its possible to create a following UI in android.
I am having a navigation drawer. It calls fragment A as the main UI. In fragment A i want to use viewpager to display different tabs.
Yes, it is possible. Just implement the Sliding Menu Library, and when you click a Menu Item from the Sliding Menu, start an FragmentSlidingActivity(Fragment Activity extends SlidingMenu's FragmentActivity to be able to slide) which has Tabs with Fragments inside.
And if you are looking for different back stack for each tab under Tab Host (like it is used to be with TabActivity which is deprecated ), you can take a look on my example project on GitHub.
Here is the link to the Sliding Menu Library.
See as suggested: https://github.com/JakeWharton/Android-ViewPagerIndicator
or this for a quick tutorial: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html

SlidingMenu Library - can I use same Sliding menu for various activities?

I am using a Navigation Drawer currently with the Android Example. I plan to change this to using SlidingMenu Library as it's easier and provides easy customisation methods. I will also use the SherlockActionBar. I will have about 4-5 different Activities and each will have different ActionBar actions depending certain states. For all the Activities, I want to display the same Navigation Drawer/Sliding menu. Currently, I am using Fragments as per the Android Example to switch and inflate new Layouts each time a new item is selected from the drawer. As this is done inside the MainActivity, all four xml layout's share the same .java Activity file which makes it long and messy.
Using the SlidingMenu Library and SherlockActionBar, can I avoid Fragments and singular Activity and link the same Navigation Drawer/Sliding menu to all the Activites?
Yes, you can use one SlidingMenu for all the activities. Make a separate base activity and implement slidingmenu in that Activity and extend all the activities in your project with that activity.

How to structure code for Activitys in a tabhost and actionbars

I want to have a few pages under a tabhost. The pages with the tabs, are accessed on about page 2/3 after application start. I am confused in how to link to the first page of the tabhost (from a page without a tabhost)
Each tab in the tabhost is a separate activity.
So when it's time to send user to a page in the tabhost, do I start the Tabhost activity (from extends TabActivity), create the tabhost, then... somehow choose which page in the tab to load? like tabhost.myTab.trigger.start(); INSTEAD of just loading one of the tabs activities directly..
So therefore anytime you leave the tabhost, and come back to it , you are recreating it, is this the correct way to structure things?
Thanks!
The TabHost method is considered a pretty old way of creating tabs within your Android application. This is especially so if you're placing Activities within those tabs.
A modern Android application uses Fragments, and uses the Action Bar framework to place those Fragments within tabs.
This can be done easily from your main Activity by using
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
This has several advantages. It means your Fragments can be placed inside of a ViewPager (so the user can swipe between them). It also means that your tabs will adapt to the device they're running on. (On a phone they may appear below the Action Bar, but on a tablet they actually become part of the Action Bar).
Depending on your implementation, this can be done is such a way that navigating between tabs does not cause the Fragments to be recreated (if that's what you're after).
A detailed guide on how to implement Action Bar Tabs can be found here
If backwards compatibility is a concern, then check out the amazing Action Bar Sherlock library.
I don't fully understand the behavior you are trying to accomplish.
Though, if you don't want to reinvent the wheel, i would recommend you to install the ActionBarSherlock demo apps1 to check if the desired behavior is already implemented as one of the library examples. If it's already done, then you can go to the github project to take a look at the source code, learn how it's done, and contribute with it.
Action Bar Sherlock demos
https://play.google.com/store/apps/details?id=com.actionbarsherlock.sample.demos&hl=en
Action Bar Sherlock Fragment demos
https://play.google.com/store/apps/details?id=com.actionbarsherlock.sample.fragments&hl=en

Categories

Resources