Android can not understand how to make fragments in the UI : First of all, even tho i can somehow understand what are the differences between fragments and activities, i can not possibly say what is better to use.

I want to create a simple drawerview. User can select from the options in the drawer menu and the main page changes. AppBar should be present at all changes, as i want the title to be there.

The UI is written in .xml format and i cant figure out how to use that in java files to be called from the mainActivity. I want to use about 4-5 different pages that change on button clicks, inside the main UI format.

I have tried working with fragments form android studio developers section, but no luck. Unfortunatelly it is not the same as JavaFX or Qt which i have some experience on Ui. Also if anyone could explain the logic that i have to follow in order to understand android UI and how to solve these kinds of problems, i would appriciate it.