I searched through the site but could not find an answer so here is my question.
I am using Android Studio 3.6 and when I start a new project and choose Basic Activity there are two fragments appearing in layout. So in layout there are .xml files activity_main,content_main,fragment_first and fragment_second. Therefore, when I start a new project, I get a different screen than the usual "hello world" screen. To add, I cannot basically edit the fragments. So, how can I back to "normal" and start without these fragments?
When you create a basic activity, you basically create an activity with two fragments. this means that basic activity by default provides two fragments that you can edit and use. basically, it's almost the same with bottom navigation activity. the difference is only in basic activity there is no bottom navigation.
if you want to make one activity app. you don't really need to use fragments. so you can just make a Empty activity instead of basic activity. if you want to make your activity fragmented in the future, you can add it later.
Related
I have made an app that is well tested and complete. It is currently using blank activity. I now want to add multiple screens so I decided to switch to a tabbed activity. I tried simple copy pasting code at necessary places in the fragment from old mainActivity but I got runtime errors. I can definitely fix them but it will take a lot of time (fixing and re-testing). Is there any other workaround. Like by converting previous activity view and pass to fragment without changing(a bit is fine) MainActivity.class . I simply don't have enough time to do major changes. Even a hint will be enough.
For making it a "Tabbed" Activity you must go through these steps:
Add a viewpager as root to your activity layout
Setup an adapter for the viewpager
Move your code from you main activity to a fragment(s)
That's it after that your activity will be converted into a tabbed activity. It might seem a lot to do at first but once you get through it you will realise viewpager is one of the most basic element in android development.
Here are some helpful links to know more about viewpager.
codepath guide
Official docs
http://blog.appliedinformaticsinc.com/android-viewpager-a-quick-guide/
If you want to just save yourself the pain of reading and understanding viewpager(which I do not recommend), Android Studio lets you create a TabbedActivity. Either initialise a new project or create a new Tabbed Activity in your project and copy paste your code from blank activity to tabbed activity.
In case you decide to make a new Activity in your current project, don't forget to change the Launcher Activity in Android Manifest.
I'm starting to build my new application and I'm trying to go the right way from the start to make my life easier later in maintaining and extending the application.
I saw applications that are probably built in fragments only. Of course, there is a host activity that hosts the fragments, but everything else is in fragments.
I suppose they have a Main activity that has the action bar and a layout to host the content in it. Everything else, including different screens such as Login, Home, Settings, Profile, ... is in fragments.
When we click on an item in the navigation drawer, for example on the Settings button, they simply change the content fragment, instead of launching a new activity for Settings.
Is that a good idea to build the main screens all in fragments, and just have one activity to display them?
Yes, it's a good idea to split up your UI into Fragments.
Some advantages:
-reuse in multiple Activities
-self-contained, modular UI
-rearrange fragments
Cons:
-it's a bit more work
-slightly higher learning curve
I am using The FragmentTabsPager, but not sure how to assign the contents of one of the tabs when the content itself is a complicated Activity that embeds ListViews, and a host of other activities. This is only for small one pane screen, so can I attach this Activity inside one of the tabs without changing the whole thing into a Fragment class? Is it right to simply change : onCreate to on onCreateView (inflate) and this becomes getActivity()?
EDIT: http://www.themobilemontage.com/
Download in the link above
Tutorial 9: Integrating Web Services Into Your Android App
http://www.youtube.com/watch?feature=player_embedded&v=QTO5a1IeBl8
The Main class is edu.gvsu.cis.toptracks.TopTrackListActivity which extends from Activity, so not sure how to convert this class (into a Fragment or FragmentActivity?) and place it as one of the tab contents if I start a new Blank Activity from template Blank Activity -> Navigation Type -> Fixed Tabs + Swipe.
Any suggestions as I tried to change the TopListActivity but not really clear what to do?
if I could convert this
There is no FragmentTabsPager in Android. You cannot embed an activity into a FragmentTabHost, which is what I assume you mean. You can convert your activities to fragments, then use those with FragmentTabHost or any of the other modern tab solutions for Android.
This is only for small one pane screen, so can I attach this Activity inside one of the tabs without changing the whole thing into a Fragment class?
No. Activities-in-tabs has been deprecated for well over two years.
I am new to android programming and currently i am doing an app with with three tabs like this -
I followed this link to develop it.
But my current app calls separate XML files for each tabs. I want to call separate activity for each activity.
Please guide me with some materials or tutorials from basic.
I want to call seperate activity for each activity.
That is not supported. The old activities-in-tabs approach has been deprecated for over two years. You are welcome to use fragments or ordinary ViewGroups as the contents of your tabs.
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.