I have a navigation drawer activity. I want to create multiple activities like the same dynamically as per user data.But I guess that we cannot create entirely new activities on run-time. So, is there a way to convert my activity(navigation drawer activity) into fragment and use it? If it is possible, how can I do it?
From You Question what I understand is that you want to create an application with an Activity having navigation drawer and different navigation items are fragments which are contained inside the activity.
You can do that easily and that is better that creating multiple activities.
read the following link and follow along same lines for doing that.
https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer
Related
I am planning to start an app from the scratch and I need to know wheather a COMMON Navigation drawer is applied through out multiple activities without using a fragment inside the activity.
I tried many examples but none worked for me. Any help should be greatly appreciated.
Yes it is possible create one base activity and implement the drawer in base activity like here. and extends that base activity
As far as I know it is not possible. I've personnaly used a single activity hosting a navigation drawer instantiating differents fragments to swipe between them.
Here if you wanna do it: http://developer.android.com/training/implementing-navigation/nav-drawer.html
The best you could have to get kind of the same result with activities is playing with transitions params in each of their class. It is kinda heavy. Use fragments for this purpose.
The following topic could bring you some work elements if you still wanna do it: Android how to add swipe Gesture on LinearLayout without onDown true
But keep in mind that it won't be as smooth as the navigation drawer with fragments.
As far it's not possible without using fragment. and why you don't want use fragment.?
Fragment is a best thing to achieve this.
Here i am attached some links.
I hope that links are use full for you.
https://www.learn2crack.com/2014/05/android-working-with-fragments.html
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
I am new to using Fragments in Android.
I started developing an app using Navigation Drawer with Fragments, but realised that I'll have more than 1 activity.
Please have a look at the diagram of my current app plan and suggest if there is a better way:
Main Activity, contains 3 fragments (you can navigate to each via the NavDrawer)
Activity 2 will be swipe tabs where each tab is a fragment. However this way my NavDrawer will not have links to this tabs/fragments.
Is there a better way? Should I avoid using a second activity completely? Or does the diagram look logical?:
My philosophy is:
Avoid creating a "God Activity". So, do not be concerned when creating a new activity. However, only create activities that make sense with your domain logic. For example, I am working on a project with the following structure:
I have a main activity working with a NavDrawer and ViewPager to make user navigation between the main sections of the APP. Some of these sections allow you to create a new record. For this new "action" I create a new activity that uses other fragments aimed at registering this new record.
That way you can have your main activity with the features that the user needs to quickly navigate and tasks used are less easily accessed by a Floating Action Button invoking the new activity.
Hope this helps.
I know it was answered before but I am still confused, if I should use fragments or activities for navigation drawer.
What is better practice? Google does not say anything about it and I am a little dissapointed.
Also, if I create a new project from Android studio with navigation drawer template, what I get is one single activity and one single fragment, but there is also separate fragment for navigation drawer and inside it, there is an interface and above it is a comment saying: "Callbacks interface that all activities using this fragment must implement.". It confuses me even more because I think I should use activities, but I am not sure.
I will keep it very simple: When you switch between activities , user has a bit of feeling as if we are taking him to another view(as if we are making him switch somewhere and the whole view is changed with a sudden blink) but when you do same stuff in one activity and changing views through fragment, it is very smooth. Moreover passing data from one fragment to other is very easy and less expensive as android says activity transactions are expensive.
Yet many times it depends on your requirement.
Keep in mind that a nav-drawer can be used for different user interactions. By the common usage as a navigation element, you will implement it by fragment(s). In this approach the drawer is placed on the left side.
An other approach can be to perform actions by pressing an drawer entry. In this situation you wont replace any fragments and only implement the drawer to the activities which should be able to perform this particular interaction (maybe: "send contact per a email")
I'm new in Android programming, researching and reading Android's manuals I've seen that you can use activities and fragments. I've understood that a fragment is a ¨small activity¨.
For example, I can create an app with buttons that create new activities or I can create an app with only one activity that open a ¨main¨ fragment with buttons that replace that with another.
So my questions are: when is more convenient to use one or another? Can I get the same functionality?
Another final question: I want my app to have a drawer similar to the Facebook app, is it a Fragment or a regular drawer with an effect?
Thanks a lot
You actually use both. A fragment cannot live without a hosting activity.
As as simple rule of thumb, use fragments everywhere that has a reusable or pluggable interface. Use activity on simple places that does not call for a fragment, such as splash screens.
For the facebook drawer thingy, this is it -> https://developer.android.com/design/patterns/navigation-drawer.html
Fragments sit inside of activities so really you have to use just activities or both fragments and activities. I would use fragments.
You really need to read this until you understand it a bit more
https://developer.android.com/guide/components/fragments.html
This question is a bit hard to word, I will try my best.
I have this android app that uses a navigation drawer, so within the main_activity, the navigation drawer would change the different kinds of fragments that I want.
Within one fragment, I want it to be able to have four tabs. The functionality of the tabs is very simple as it basically just display some pictures and data. However, I don't think android allows you to have a tabhost within a fragment.
I can achieve a similar result by creating my own buttons at the top and it dynamically changes the View that is within this fragment, however, I am wondering is there a more intuitive way of achievement the same result?
You can use TabHost inside a Fragment just fine. A TabActivity is not necessary to host the tabs. TabActivity only provides some functionality that you can also add to a Fragment yourself. Check out the TabHost docs, especially the section about addTab(). You can also search here on SO and you will find very helpful posts like this one.