How to create a Fragment (Begginers at Android Studio)

0
242

Step 1:- Right Click on Package and go to New -> Fragment -> Click on Fragment (Blank) then Name the Fragment

Step 2:- Erase all the default Code expect OnCreateView

Step 3:- Click the Code like below:

public class ExampleFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_category, container, false);
        
//Now right your code here.


//If You want to declare any variable then write a code like

TextView txtExample = rootView.findViewById(R.id.txtExample);
        
        return rootView;
    }
}

Now its done.

Thanks…

If you like this post then please share with your friends who want to learn code.

LEAVE A REPLY

Please enter your comment!
Please enter your name here