Fragments vs. Activities for Tab Navigation - android

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/

Related

Android TabHost show tabs in all the activities

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.

Android menu option problems in fragments

I am developing an application which has a navigation drawer with 9 fragments.
Two of nine fragments have tabs(4) interface implemented. Each tab has its own menu option and each fragments (other than with tabs) have their own menu options.
Now the issue is,
When i access or switch a simple fragment(without tabs) from the navigation drawer then its menu options and working fine.
BUT
When switching from a tabbed fragment after accessing , its menu options now appear on every other fragment in the navigation menu.
For example
I access and switch from fragment "A" ->everything goody including all menu options
I access and switch from fragment "B" (with tabs) then all the other fragments have its menu options.
If I didn't explain my problem effectively then do ask me again in the comments. I have been stuck with this problem since a week. Maybe a small problem or something else but do need some help from the people here.
////update//
SetHasMenuOptions implemented in each fragment. All fragments working fine except the tabbed ones
The main problem is, after accessing tabbed fragments all the menu options of other fragments are replaced by the tabbed menu options.
3 posting a question through my phone cant post code sample.
Actually first i had problems like this with every fragment but then i implemented sethasmenuoptions
And menu.clear() in each fragment and every fragment seems to work
Like it should except the tabbed ones
Hope this info helps
Thanks
Use transaction.addToBackStack(null) while fragment transaction and in layout set background colour to the fragments .

android converting activities to fragments

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.

Can a navigation Drawer be declared on a Fragment?

I got a navigation drawer on the activity of my app, but once I get the fragment parts of my app running (through a fragmentActivity) I have trouble programming a navigation process over there. I want my users to be able to navigate from one fragment to another fragment using the navigation drawer, making life easier.
Does anyone have a solution to this?
I think what you want is a ViewPagerIndicator, and to use a ViewPager with a FragmentPagerAdapter to page your Fragments.

How to make tabs visible in whole application?

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.

Categories

Resources