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
Related
I am developing an android application which is the android version of existing iphone app.
In iPhone app, there are five bottom tabs (As iOS support these). Every tab has more than one activities.
For example:
Tab 1: It has activity 1 which starts activity 2 and so on with in the single tab (Tab 1) and also back navigation too.
I have already read following but still have doubts.
http://developer.android.com/design/patterns/pure-android.html
http://developer.android.com/design/patterns/actionbar.html
http://developer.android.com/guide/topics/ui/actionbar.html
My questions are:
1) What is the best replacement of such kind of tabs in android. If I use action bar tabs then It will the right approach?
2) If I use action bar tabs, then is it possible to start different activities with in the single tab and action bar back navigation too?
3) When I should use Action bar tabs, Top tabs or bottom tabs in android (Tab Host still not deprecated in the Android)
Please guide me. I am very confused about tabs in android.
1) You can use Navigation Tabs! (and With that probably you'll use Fragmnets and not Activity)
2) Of course, the Navigation Up is really an usefull thing
3) Bottom tabs is possible with a Custom Layout.. I think it's not best thing, but you can do it!
It's a very short anwser but you can check everything in developer training and checkin samples that you find in your SDK
I'm looking through the ActionBarSherlock samples demo, and I see that the List Navigation and the Tab Navigation both make use of the ActionBar's setNavigationMode method. This tells me that you can only have one or the other. If I want the user to have list navigation to move around between activities but I want some activities to have tabs, is there a different way to add tabs than via navigation mode? Is it against ActionBar design guidelines to use both? I don't look at tabs and consider this to be a navigation feature, so I find it odd that you get one or the other.
This tells me that you can only have one or the other
Correct. Bear in mind that with action bar tabs, Android will convert you to list navigation, on its own, in certain configurations, whether you like it or not.
If I want the user to have list navigation to move around between activities but I want some activities to have tabs, is there a different way to add tabs than via navigation mode?
You can use a ViewPager with PagerTabStrip or the tab flavor of ViewPagerIndicator.
Or, you can go retro and use TabHost and TabWidget.
Is it against ActionBar design guidelines to use both?
The design guidelines refer to them as separate options for "View Controls". More importantly, given the automatic conversion of tab navigation to list navigation, it would be seriously confusing for the action bar to have two Spinners' worth of navigation choices.
I want to create a app with a menu at the bottom of the screen. This menu should be visible any time the app is started.
Im working with fragments, so the menu is one fragment.
So I have only one Activity as controller which loads different fragments above the menu fragment.
Because I want to create clean code, i dont know how to solve the problem that the Activity class is too big.
In other words, i want to create different controller within the same activity. How to do that?
Is there another approach to solve this issue?
You should be using the split action bar This allows you to put the Actions and overflow menu on the bottom of the screen. I believe you can use Action Bar Sherlock for backwards compatibility to older versions of Android. See their site for detail.
Another possibility is to look into using fragments with the ViewPager . Here is a library that works with compatability as well ViewPageIndicator . Here is a blog post , like I indicated in my comment I got this working with the tabs showing at the bottom and the pages above.
Im creating an app with an action bar, and the tabs go to different web pages. When the user clicks on a different tab I want the previous tabs web page to stay in the same state (ie not reload when the tab is pressed again).
Whats the best way to do this? Separate activities? Fragments? Multiple web views in one activity?
Thanks
Use tabs in the ActionBar, which allows you to use Fragments. When changing tabs, the Fragments will replace, and the previous Fragment will hold its contents.
See Action Bar - Adding Navigation Tabs | Android Developers
I think you have to use one webview and store content of each page locally for example in DB and then make yourself some navigation bar and reload your webview content by navigation bar.
For example navigation bar can be orginized like LinearLayout with Buttons childs.
If you use this way - for example you can download 10 web pages at home with your wi-fi and then minimize your app and go for a walk and after some time (even if you use other apps) you can restore all your information from DB, but if you use only fragments in tabs you can loose you pages because of memory lack.
If you use fragments or atcitvities in tab - you can't be sure that previous content will be saved (but you can still do it by adapter and tabhost (there are quite enough samples how to use fragments + tabs)
PS. this is only my opinion and i haven't tried it yet, but i think local store is a best way to resolve your problem.
I'm building an application that requires Tabs, which are now deprecated. The dev guide says to use Fragments to replace the tabs instead. However, my application needs to have fragments within each tab, which means fragments inside fragments, which isn't allowed. Does anyone know of a possible work around for this?
While the action bar support for tabs is designed to make it easy for the contents of a tab to be a fragment, that is not strictly required. You could use ViewFlipper, repeated calls to setContentView(), or something to arrange to change other stuff when the action bar tab is selected.
Prior to the native action bar (Android 1.x/2.x), either stick with classic tabs, or use something like Action Bar Sherlock to get an action bar and tabs.
I fake tabs by having a "tabs" fragment across the top that contains multiple toggle buttons. Below that I have a merge view containing a separate fragment for each tab.
I respond to taps on a toggle button by toggling the other buttons "off", showing the fragment for that "tab", and hiding the others.
its little late , but yes you can :) here's an example
but for fragment inside fragment inside tab isn't an android native way, you have to start a new fragmentActivity if you want to show detail of fragment. you can but is not an android way !