Android Newbie: Quick Solution for Fragments API

Google updates its android sdk very often. They include many things and fragment api is one of them. It is very interesting and helpful api which will let you create dynamic things. But if you are new to android you might be confused with it.

In older version of android when you create a new android project, you don’t have to deal with fragments api. But in newer version Google automatically inserts fragments api and its related code. If you don’t want this code in your program then there is one quick solution for it.

Let us create a simple Android project by
File->New->Android Application Project

Give your project a suitable name and fill all the required fields.

You can see that there is another xml file named “fragment_main.xml”. Open this file and copy all the code in this file.

Now open “activity_main.xml” file. Delete all the existing code in it. Then paste the code that you have copied from “fragment_main.xml”.

Now delete the “fragment_main.xml” file. You don’t need that now.

Now open you java file “activity_main.java”.
Delete the class named “PlaceholderFragment”. You don’t need it.

Now go to “onCreate” function and remove the if condition.

Now run your application. It will give you same output as with use of fragment api.

Hope this article will help you. If you have any question or suggestion, feel free to comment. Thanks.

Tags: Android
comments powered by Disqus