Add a fragment without xml file in Android studio chipmunk

Viewed 18

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?

1 Answers

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);
    }
}
Related