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.
Asked
Active
Viewed 3,153 times
0
-
For a person who worked with Android, its hardly half hour work to copy paste code from activity to fragment, may be more in case of bigger projects. but in either case, there is no direct method to switch, yiu have to either publish your code for someone to do it for you or umderstand the lifecycle of Activity and Fragment to isolate codes for copy paste at right spots. – Mohammed Atif Jun 18 '17 at 18:43
-
1ViewPager + TabLayout + Fragments + PagerAdapter... That's a lot of changes for "simple" – OneCricketeer Jun 18 '17 at 18:43
-
It might not sound complex. But trust me it is. I have switched to tabbed view before on simple projects without problems. But this is not because of inter-connection of lifecycle and inner class. Seems there is nothing that can be done. I will try to work with copy-paste hoping I resolve errors soon. – Lcukerd Jun 18 '17 at 18:55
-
well @lcukerd, i have seen people converting whole project into fragments from activity amd thats the only challenge you have. because omce you habe fragment, it can easily be used with viewpager and it takes 4 lines extra to attach it to tabbed view. **seems like nothing can be done** may be you ddnt copy paste properly. – Mohammed Atif Jun 18 '17 at 19:08
1 Answers
1
For making it a "Tabbed" Activity you must go through these steps:
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.

Rohan Bhatia
- 1,870
- 2
- 15
- 31