[FIXED] Add a fragment without xml file in Android studio chipmunk

Issue

I want to add a fragment to a project I downloaded without the XML file as the XML file I’m gonna use is already provided, except that in previous versions of android studio you could uncheck the create layout file checkbox
in the latest version, it doesn’t give you this option and if I create a layout file and then delete it, it gives me an error, how to fix this, please?

Solution

You could create a simple class that extends from Fragment, using your existing layout file to it:

public class YourFragment extends Fragment {
    public YourFragment() {
      super(R.layout.your_existant_layout);
    }
}

Answered By – Gaya Touak

Answer Checked By – Cary Denson (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published