Question 05: Write a program to display 10 students basic information in a table form using Table layout.
Download hole Program / Project code, by clicking following link:
List different attributes which can be used with any layout managers in Android Studio?
In Android programming, an Activity is a fundamental component of an Android application that represents a single screen with a user interface. It is an essential building block that defines the visual and interactive components of an application. An Activity is responsible for managing the user interface, handling user input, and coordinating with other components of the application.
Different layout managers in Android Studio support a variety of attributes that can be used to customize the layout of user interface components. Here are some common attributes that can be used with most layout managers:
- android:id: This attribute is used to assign a unique identifier to the view, which can be used to refer to it programmatically.
- android:layout_width: This attribute is used to specify the width of the view. It can be set to a specific value, such as "match_parent" or "wrap_content", or it can be set to a specific pixel value.
- android:layout_height: This attribute is used to specify the height of the view. It can be set to a specific value, such as "match_parent" or "wrap_content", or it can be set to a specific pixel value.
- android:layout_gravity: This attribute is used to specify the gravity of the view within its parent layout. It can be set to values such as "center", "left", "right", "top", or "bottom".
- android:layout_margin: This attribute is used to specify the margin around the view. It can be set to a specific value or a combination of values for top, bottom, left, and right margins.
- android:padding: This attribute is used to specify the padding inside the view. It can be set to a specific value or a combination of values for top, bottom, left, and right padding.
- android:background: This attribute is used to specify the background color or image of the view.
- android:text: This attribute is used to specify the text displayed by the view.
Programming Code:
Following code write in: MainActivity.java
package com.go2collage.practical_05;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Following code write in: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="go2collage"
android:textSize="24sp"
android:textStyle="bold"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="20dp"
tools:ignore="HardcodedText" />
<!-- Table Heading -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sr. No."
android:layout_marginRight="25dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText,RtlHardcoded" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Name"
android:textSize="18sp"
android:layout_marginRight="25dp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText,RtlHardcoded" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 1 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 1"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Raju Taak"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delhi"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 2 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 2"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pinku Teli"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lakhnow"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 3 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 3"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abdul Salam"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Parbhani"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 4 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 4"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kamal Hasan"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chennai"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 5 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 5"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pritam"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kolkata"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 6 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 6"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anjali Chauhan"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pune"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 7 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 7"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balaji Ramu"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Guwahati"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 8 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 8"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shivam Dube"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aurangabad"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 9 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 9"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dawood Dalvi"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mumbai"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
<!-- Table Data cell 10 -->
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 10"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Eknath Shinde"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thane"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</TableRow>
</TableLayout>
Output:
0 Comments