Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove fragment layout in beginning of creating a new app in ADT?

After the latest update of the Android Developer Tools there is a problem I faced whenever I create a new project. It forces me to create a fragment_layout.xml as well. So in the hello world program there is too much of code.

But in previous one only MainActivity.java and activity_main.xml appeared.

Is there any way to remove only the fragment_main.xml and the extra code in the MainActivity.java.

One way is to un-mark the create activity part in the beginning but it will not create the MainActivity.java too.

like image 616
Rajan Maurya Avatar asked Mar 29 '14 18:03

Rajan Maurya


People also ask

What is fragments in mobile application development?

A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.

How do you put a fragment inside an activity?

Add a fragment to an activity You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.

What are activities and fragments in Android Studio?

Activity is an application component that gives a user interface where the user can interact. The fragment is only part of an activity, it basically contributes its UI to that activity. Fragment is dependent on activity. It can't exist independently.


1 Answers

To remove fragments from your new wizard-created app:

  • Change the type of MainActivity from ActionBarActivity to just Activity.
  • Delete the whole if (savedInstanceState) statement from MainActivity.
  • Delete the PlaceholderFragment class from MainActivity.
  • Replace the contents of activty_main.xml file with the contents of fragment_main.mxl or your own layout.
  • Organize imports and clean your project.
like image 50
scottt Avatar answered Oct 07 '22 00:10

scottt