0% found this document useful (0 votes)
20 views

FINAL

The document describes an experiment to create an Android application using fragments. It includes the code for the main activity, activity layout, and four fragments. The application displays text in each fragment on the emulator. The student learned how to create basic Android applications and fragments, and display the output on emulators.

Uploaded by

Manohar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

FINAL

The document describes an experiment to create an Android application using fragments. It includes the code for the main activity, activity layout, and four fragments. The application displays text in each fragment on the emulator. The student learned how to create basic Android applications and fragments, and display the output on emulators.

Uploaded by

Manohar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 3.

1
Student Name: Manohar Chaudhary UID: 21BCS4422
Branch: B.E./CSE Section/Group: 21BCS-FL-603-B
Semester: 6th Date of performance: 26/03/24
Subject Name: MAD LAB Subject Code: 21CSH-355

1. Aim: Create an Android application using Fragments.

2. Objective: The objective of an Android application using Fragments can be to


enhance the user interface and improve the overall user experience by leveraging
the benefits of fragment-based design. Fragments allow developers to create more
modular, flexible, and scalable UI components.

3. Apparatus/Requirements:
Computer with Android Studio installed and configured, Internet Connection,
Android device for simulation.

4. Script:
MainActivity.java:

package com.example.fragments;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="2"
tools:context=".MainActivity">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment1"
android:name="com.example.fragments.Fragment1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment2"
android:name="com.example.fragments.Fragment2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment3"
android:name="com.example.fragments.Fragment3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment4"
android:name="com.example.fragments.Fragment4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1" />

</GridLayout>
Fragment
Fragment.java:

package com.example.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;

public class Fragment1 extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_1, container, false);
}
}

activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FA9A"
tools:context="com.example.fragments.Fragment2">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="My name is Murli \n 21BCS5810" />

</FrameLayout>
5. Observation:

My name is Murli
Hello Everyone 21BCS5810

I am an aspiring CSE I am improving my


Students Coding Skills

6. Learning Outcomes:

 We learnt how to create basic applications in Android Studio.


 We learnt how to create fragments.
 We learnt how to show the output on Android emulators.

You might also like