I have an app in which I have three tabs on the ActionBar and and each tab has a Fragment associated with it in the ViewPager such that the user of the app can scroll between the different tabs/fragmens using a swipe gesture. So there are 3 tabs and 3 fragments and there is a one to one relation between them.
What I want to achieve is that inside each tab there should be 3 fragments and user should be able to navigate between them using the swipe gesture. Similarly other tabs can also contain different number of fragments and user should be able to navigate between them. So in this case there are three tabs and those can have "n" number of fragment such that there is one to many relationship.
How can I achieve such a behavior using or do I have to change my current approach and do something else. Kindly provide me a path here, I am stuck on this for quite a sometime.
Related
In one app, I would like to use three activities with a swipe view with three tabs; each tab triggering an activity
(In the doc I have read about ViewPager and fragments, but it is for a different purpose); if it is possible how can i do that ?
if it is not, must i break my app in three app ?
Thank you.
Having activities in tabs has been deprecated as a technique for over five years.
Whether you use fragments or views for your ViewPager pages is up to you.
if it is not, must i break my app in three app ?
No, you can have multiple fragments or multiple views within one app.
Make one activity with three tabs and one ViewPager. Each tab then change fragments in the ViewPager
I'm currently designing an android app and tried several kinds of general setups, each seeming to have it's downsides.
The app generally consists of three screens (A, B, C), each of those has a list. On list selection it should change to a detail view (A1, A2, A3).
I want each detail view to be swipeable back to it's list.
All I'm sure about is that I have three buttons in the action bar which let the user switch between A, B and C.
Beyond that I tried those setups:
The whole layout is one ViewPager with six fragments. Downside: I have to implement the logic "when and where to swiping is allowed" myself - seemed wrong to me
The layout consists of three fragments, each containing a Viewpager with two fragments. The Viewpager-Fragments are replaced on Actionbutton-Clicks
Downside: I have to forward all State changes to the inner fragments
The layout consists of one Viewpager that gets its Adapter replaced whenever an actionButton is clicked and thus always only has two Fragments at a time
Downside: Fragments are often destroyed and recreated
I hope I made my problem clear.
What general design would you recommend?
I would recommend having fragment with viewpager that would show three fragments with lists. Now, on list item select, I would replace this fragment with item details. When user want to swipe back, i would add custom gesture handling that would call onBack. I would argue if such gesture handling is good design but I'm guessing that you simply need to mimic IOS behaviour (which probably most of us have to do too damn often)
My App (minimum API 14) uses an ActionBar with 3 tabs.
The tabs are:
i. enter data (approx 10 fragments)
ii. manage data (15 fragments)
iii. view data (8 fragments).
Each tab has a default fragment, but then has multiple fragments depending on user choices.
I would like the user to be able to swipe between the 3 tabs (by swiping the content) hence I need to use ViewPager and the compatibility library v4.
The advice I have picked up (after much research) is to use a MainActivity which hosts the ActionBar and tabs with fragments for the tab contents. But I'm worried about the number of fragments. Also some of the fragments need to use date and time pickers which means DialogFragments coming out of fragments. It's starting to get very complicated.
Does anyone see any problem with my using Activities instead of fragments for the tab contents?
Fragments act on the UI side just like activities except you can combine multiple together. So you don't need to create a different fragment based on user choices, you just need to change the fragment just like how you would change an activity dynamically.
Also if you want to use ViewPager, you are basically forced into using fragments.
The nice thing about fragments is that they are reusable, so most likely you only need a few fragments and then you can combine them in different ways for the different use cases. This also makes your tablet UI a lot easier to create.
For reference: http://developer.android.com/guide/components/fragments.html
I have nine tabs(say 0 to 8), displaying only five tabs on screen.
The five tabs will be 0 to 3 of those nine tabs and fifth tab will be MORE Tab.
MORE tab will show Activity with GridView showing Image+Title of remaining nine tabs(say 4 to 8).
Now on click of any item(Image+Title) in GridView will replace the MORE Tab Image+Title and its content/activity with its respective activity.
I am able to replace the tab indicators(Image+Title) but struggling on replace its respective content/activity.
As on other similar thread they had suggested to use clearAllTabs and add/recreate require tabs again. But i feel clearing all tabs just to replace one tab is heavy.
I am using the TabActivity with Intents. As i know TabActivity is deprecated by its old app initially it had only 5 tabs but now requirement is to add few more tabs.
Need your help to implement this. If it not possible with TabActivity, then switching to fragment tabs does it help me?
I trying to implemtent this Image
I would recommend fragments for sure. I've used TabHost in the past and it was very problematic.
You can simply have Button at the top that control the visibility of the fragment below. With this way, you'll even be able to add transitions.
This link give a little more information on that topic. Separate Back Stack for each tab in Android using Fragments
I'm currently developing an application that has a tab bar, and 3
different views: the first is a master-detail, the second one a
gallery, the third is a simple webview.
I was using the TabActivity, but since Android 3.0, this class is
deprecated and Android reference
suggests to use Fragments.
I switched then to an ActionBar, with Tabs and Action
Items. Inseide the first tab item I have a layout with 2 fragments (my
master-detail view). When I switch through tabs I want that my layout
change as I described above, so I thought to hide the left fragment
(the master listview) and work only in the detail fragment.. but with
this solution I have only one main activity with a lot of fragments
attached to it, and for each fragment displayed I need to modify the
Action Item shown and handle different actions in
OnOptionItemSelected.
Is this a good way to implement this kind of
application or should I consider different solutions?
You should have a single fragment container where the fragments are replaced depending on the tab selected.
One activity and multiple fragments is the right approach.