For creating a fragment we only use two things:- Fragment class Fragment xml layout In the below discussed example we need to show different fragments on button click event. So, we will be creating two layout files and two different classes. Here goes the code for first Fragment: FirstFragment.java package com.example.fragementdemo; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class FirstFragment extends Fragment {
Learn Android tutorial Android Basics in Kotlin, Advanced Kotlin, Kotlin Fundamentals, Android Developer Fundamentals (Java)