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.
Related
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)
I have implemented an ActionBar with 3 tabs in an android app. I also used ViewPager to switch between different tabs. Every tab is defined in a fragment.
The last tab is called "Setting". I have two different settings. One is "Simple" setting, and the other one is "Advanced" setting. How can I implement these two different settings in the "Setting" tab. Should I make kind of sub-fragments or two new tabs inside the main tab which is "Setting" tab? Can I also for example create two buttons at the top, and switch between them? Or any better idea? Which solution is easier and more efficient. I'm a newbie in Android.
I want to make something like this:
Hope this help
Take SettingFragment as Host fragment
Place both buttons on top and ViewPager below buttons
Take SimpleFragment and AdvanceFragment as items in ViewPager
Inside my app I am using navigation drawer for my navigation. For each "page" I am using fragments (like showed here: http://developer.android.com/training/implementing-navigation/nav-drawer.html). It works completely fine, but now I want to create swipe tabs. I want to display those tabs only on one of the fragments. Problem is, that tabs are displayed on all fragments, which is ofcourse perfectly normal because tabs are inside action bar. What should I do, to display tabs only on one fragment?
From what I have understood, you are interested in showing action bar only in a particular fragment (not visible when swiping in subsequent fragments). The best way would be to code the action bar in fragment instead of using the action bar in main fragment and then creating swipe views (or sub fragments).
Hope it helps.
I have gotten my tabs up and running with Sherlock Fragments. So i have two tabs and two fragments. Now what i want is that when i click on a button in one of the fragments, I want another fragment to open up, but it should be inside the tab that contained the original fragment. Can anyone show me how this can be done ?
Actually Nested Fragments are not possible directly. I had a similar issue and but the Fragment to be shown was small and simple. So I just played with setVisibility() as LinearLayout.GONE and LinearLayout.VISIBLE
On the Fragment initialization, I hid the second layout and when I need to show the other fragment, I hid the first layout and showed the second layout. It worked great for me!
I have to show two tabs each containing ListFragment classes. On clicking any item of the list, it's details should open on the right panel on landscape views. This is much like the official Android fragments example.
What I want to achieve is that on the left side of the layout the list view should be in tabs, i.e. two list views within tabs. On clicking any item the details should open on the right. Till now, I can show tabs and details, but the details are not showing up on the right. They open as a new activity.
Tab Navigation can be an option, but due to some design restraints in my app, I can't use that. Please guide.
Please check this android blog http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html It has a complete tutorial of how to use fragments as a Master-Details View.
I came to a solution. I am explaining how I did it, in case someone needs it.
I wanted to make tabs on the left fragment. Due to design constraints, I could not use Tab Navigation, as I had to use List Navigation too.
So, I made a new fragment placed over the left fragment and inflated it with two buttons. On different button clicks, I used FragmentTransaction to add new fragment to the left fragment.
On button click listener I used fragmentTransaction.replace method.