What is the best way to develop an android app with multiple screen content,
changing it with an drawer layout like the picture. How can I do that? By using
fragments with one activity and change each fragment by old fragment, or choose another technique?
Now i'm using one activity and replacing fragments.
Thanks in advance.
If the format of all the screens is the same, with essentially the same layout. Then you would only need one fragment that is updated based on which item in the drawer was selected.
If the screens are different then the original approach with multiple fragments and one activity is recommended.
Related
I am coming from iOS and working to port an iOS app on android. In iOS there is the storyboard where you can connect different view (activities) and embed them into tab bars and navigation bars. I am having an issue to understand what is the best way to implement bottom navigation in android...
Let say I have 3 bottom navigation items with the following
tab1
page1.1
page1.2
tab2
page2.1
page2.2
page2.3
tab3
page3.1
page3.2
page3.3
As an example in tab1 I have page1.1. Then let say I have a button in page1.1 which bring me in page1.2. If I go back from page1.2 I want to go back to page1.1. Same story for page2.1, I can go to page 2.2 and from page2.2 I can go to page2.3. I also want to go from page3.2 to page 1.2
I have read fragments are the best way to do it (each page.x is to become a different fragment with a different layout) but it does not seem very easy. I have also read I can use activities but many suggest not to use it
What do you recommend that I focus on? Are there any other solution to consider on top of fragment and activities? Thanks
You should use Fragments with a Single Activity. If you don't, you will have to copy/include one bottom bar in multiple Activities. It might be useful in some cases however when Activity is switched, your bar will redraw which might turn out to be a bad user experience.
I have read fragments are the best way to do it (each page.x is to become a different fragment with a different layout) but it does not seem very easy
Using Fragments might actually make it easier than if you use Activities. If you use Fragments, you can have one Activity be in control of every fragment that is being displayed, meaning that you can control navigation based on which fragment is being shown. This way, you can handle some special scenarios that do not fall into usual navigation behavior.
Doing the same in Activities would be a little more difficult since you'd have to continuously pass around data in Intents and it would be difficult to control the behavior since your logic will be spread across Activities.
What do you recommend that I focus on? Are there any other solution to consider on top of fragment and activities?
These two are only recommended solutions. If some of your UI elements are same in all pages while some part of it is changed constantly, then its best to use Fragments with single Activity. For screens that are completely different or that are not part of your navigation flow, you add more Activities for them instead of Fragments.
For example, You can use Fragments in One Activity with Bottom Navigation Bar, but for settings screen or profile screen, you should make separate Activites.
I am building app right now. I am trying to follow all design patterns and google suggestions for building responsive apps.
Firstly, my app will contain navigation drawer.Of course my app will have several activities. So I have searched the best way to have navigation drawer on all activities, I found that the most correct way is to use some BaseActivity class which will have navigation drawer in its layout and framelaout for storing each activity representation(container for fragment). It can hold fragment, but the problem is that only one fragment.
So I have faced this problem. I am going to design following activity
So as in the picture I wanna to have image slider at the top , and some other layout parts under this slider for example grid layout, list or something other.
I think it would be better to separate image slider and other part, for example when my scree will be in landscape orientation it should be replaced but something other.
Futhermore others activites also gonna to have several independent parts for example list and anything other widget.
But as far as my activities should extend BaseActivity class, they would have only one place(container) for storing fragment.
I have tried to think about ways to solve this problem , and I have only one idea is to create several fram layouts in base activity(equal to max fragments used on child activities) and setting them visible and invisible depending on needs, but this approach pretended to be only way of hidding problem.
I don't know what is the most correct way to implement such type of application, so I need help or advices from more experienced developers to build my app correctly and bring user good experience.
I hope you can help me.
Thanks.
To start with, the container in your BaseActivity does not have to necessarily be a FrameLayout. For example it could easily be a LinearLayout with android:orientation="vertical", so that all fragments you add in it will stack one below the other.
Also each fragment can has other nested fragments in itself (although that's generally not the best practice, as usually it indicates some bad UX decisions).
Both those said, I think you just use the first point I made here. Now if you choose this one, I'd expect the question how to handle tablets and other big screens? Best way to handle them is to create a new landscape layout for your BaseActivity, where the fragments container might be different, for example a RelativeLayout, a LinearLayout with orientation="horizontal" and so on.
Good luck!
I have to write a simple app which will look different depending on the screen size.
On a small screen it would have a list of items and after click it will display details. On a bigger screen it would have a list of items and details next to it.
My question is: should I use fragments to do such an app or just write different layouts and place them in layout-large or layout-land folders?
If it is a new app I would always go with fragments, basically for future proofing your app. You may have a single list now, but later you may want to introduce a menu for selecting different types of lists for example. By using fragments, on a phone you can use two activities, one for selection, and the other for the list, but on a tablet in landscape mode you can place the selection and list side-by-side.
Coding for possible app enhancements and features now, saves you time and headaches later.
You can do it in both way , but the suggested solution is using fragment
check this out :
https://developer.android.com/training/basics/fragments/fragment-ui.html
and this :
http://www.vogella.com/tutorials/AndroidFragments/article.html
You should use Fragments, since Fragments were created for that purpose, besides, if you make 2 layouts, you will have to do 2 completely diferent layouts and that'll mean that the activity would not handle that, at least not in an easy way, so try fragments to achieve that, the official documentation example is a case like yours, that would be enough to believe that the correct way to do it is with fragments.
I am making my first android application with the ActionBarSherlock.
The application will always have an action bar consisting of 3 tabs (first tab selected by default).
The app could be extended for use with a tablet.
I have been searching the web, and following the android development guides, however I am finding a few things confusing.
The first tab screen will be a list view with a list of items, onitemselected should send the user to a screen which features more details about that item.
When should I use a fragment? Should each tab be a fragment?
Or, should each tab call a new activity, which consists of fragments?
And, if using fragments, should I place them in different classes, or embed them within an activity??
Appreciate any help, thanks.
you should probably read these two links first.
http://android-developers.blogspot.com/2011/09/preparing-for-handsets.html
http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
If you plan to make an app that work on both phone and tablet. It is a good idea to use a fragment, and then use a shell activity to wrap that fragment.
My experience with Fragments is mostly on ViewPager, so I am not entirely sure if it applies here.
In Android, you should use Fragments as much as possible. As a general rule of thumb, imagine you are translating the UI from phones to tablets, elements that can stay together in the same configuration should be a Fragment.
There is a Fragment subclass called ListFragment, so you might want to look into that for your first tab. (ListFragment is for Fragment like ListActivity is for Activity)
There is also a tutorial I found to deal with fragments. Did not really look into it but I hope it helps.
http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
As for ActionBar / ActionBarSherlock, I have absolutely no experience withit so someone might want to add to that.
I'm currently creating an app in which the main screen is build up out of 2 Fragments.
When the user selects options on the main screen, one part of the screen gets replaced by a new Fragment, all pretty much basic stuff.
Now I'm trying to create a screen with several tabs, which all open a new fragment inside them. I had this working with regular intents, but that was before switching to Fragments.
I read that this is possible by using a FragmentActivity, but sadly you can't replace a Fragment with a FragmentActivity, simply because the transaction won't let you.
Is there any way of doing this inside an ordinary Fragment? Or should I try mimicking the behavior by using a layout with a fragment inside which gets replaced by another one at the press of a button, much like the main screen? (Or won't that work due to fragments in fragments?)
There is an example in Android's support library that describes what seems to be what you need. You can find it here: FragmentTabs.