
Step 2) So now our blank project is created and going to your textview of this java file activitymain.xml and instead of relative layout, we are going to use linear layout here, therefore, change this relative layout to linear layout. Read Here Start New Activity on Button Click in Android


Step 1) First create a new project for this fragment example name project as Fragment.Then choose the default, minimum STK and, note that we can use fragment above API 11 so it’s better to use API 11 or above to use fragment in a better way so we will use API 11 or android 3.0 which is honeycomb and then click next and create a blank activity, click next and then leave all the field as default and click finish. Please follow the steps below in order how to use fragments in Android: An activity can contain a various number of fragments. The biggest advantage of the fragment is that it simplifies the task of creating UI for multiple screen sizes. We can combine multiple fragments in a single activity in order to build a multi-pane UI and reuse a fragment in multiple activities.

A Fragment represents a behaviour or a portion of user interface in an Activity.
