I am developing an android application in which i have created five tabs and when i click any of the tab a new activity is called ,
my problem is
like i go from one tab to another tab and a new activity is called ,till then the tabs are visible but when i go to next activity from that activity the tabs disappear ,
all tabs are visible on five activity which are called on tabs but not in the inner activites like
Activity1 ---- > Activity2 ---- -----> Activity3
my question is how can i make the tabs visible in all the activities in the application
Since ActivityGroup is deprecated, I suggest you use Fragments and the ActionBar. Use the compt lib to support older versions of Android.
The sdk samples has a good example you can refer to.
Related
In my Android app I'm using TabHost to work on some tab functionality. tab works fine. but in my app each tab contains several icons related to activities and when each activity starts it take over the whole screen. instead I want to show tabs when all the activities are running.
for instance take following screen as my tab view.
and when I click on the icon the second screen is as follow.
in there I can't see the tabs and in my case I wanna be able to see the tabs in the second activity too.
how can I implement this. can I use Fragments in this. Thanks and regards.
I have made a nice app with a whole bunch of activities , then i needed a navigation drawer and found out that you need to have only one activity for the whole app and the individual different screens should be fragments that are inserted at runtime.
my question is :
How to convert the entire app to use fragments instead of activities ? (eg: how to preserve activity hierarchy , show a main activity when the user opens the app , different actionbar for each screen , etc...)
There is no magic converter, you need to convert manually each activity to be extended from Fragment
and add few must methods like onCreateView for the fragment instead of SetContentView of activity.
Regarding the actionbars, it sits on the Main Activity so you need to create callback events from each fragment to the main activity in order to control the action bar.
Navigation drawer has nothing related to fragments.
If you wish you can put it into activities also.
What I created was a BaseActivity with layout having navigation drawer and all other activities extend BaseActivity so that each of your activity will have drawer. Only you need to change content page for particular activity.
happy coding.
I am trying to implement a tabbed navigation in my android app, however I want to run a different activity in each tab. I've been reading the android development page and they insist on using fragments for navigation over activities. From what I understand, you cannot have a fragment class by itself, it must be contained in an activity.
Is it possible to create a new activity for each tab and run that activity in the onTabSelected() function, while displaying the UI for each tab from the fragment within the running activity?
TabHost has been deprecated for Fragments, but I have been unable to find a way to navigate through activities by tabs.
Nope, you don't want to have separated Activities for each tab (although I've seen such apps :() . Basically - Activity is a top-container, and any TabHost View is a child of such Activity. Switch to the Fragments, check this out:
https://stackoverflow.com/a/6891923/1434631
this: http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
and this: http://neilgoodman.net/2012/03/12/working-with-fragments-on-android-part-2/
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.
I've set up a TabHost containing a TabWiget with three tabs in it - each of which loads a separate activity. This all works well, switching between them is smooth, state drawables on tabs work well and so on.
However, in each activity (i.e. tab contents) I need to load further activities while still showing the tab bar at the top. Problem is, doing this:
startActivity(new Intent(this, SomeActivity.class);
loads the activity, but with a sliding animation. This looks weird when I'm supposed to have a fixed tab bar at the top (i.e. it slides out and back in). Switching activities with the tabs does not trigger this animation.
How can I load an activity without the sliding animation? I have no problem doing it through the TabHost if that's required, but its API didn't suggest this was possible.
Using ActivityGroup for the tab contents, and then managing their content with getLocalActivityManager seems to be the trick: http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/