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

MAD Lab Assignment 5: Name: Zain Mushtaq Sap ID: 70067944 Section: B

This document contains code for a student information Android application. It includes XML layout files for the main activity and list item, and a Java class file for the MainActivity. The main activity layout contains EditTexts for name, department, and CGPA, a button, and a list view. The list item layout contains a text view. The MainActivity code gets the user input from the EditTexts, adds it to an array on button click, and sets the array as the adapter for the list view to display the student information.

Uploaded by

MUSHI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
180 views

MAD Lab Assignment 5: Name: Zain Mushtaq Sap ID: 70067944 Section: B

This document contains code for a student information Android application. It includes XML layout files for the main activity and list item, and a Java class file for the MainActivity. The main activity layout contains EditTexts for name, department, and CGPA, a button, and a list view. The list item layout contains a text view. The MainActivity code gets the user input from the EditTexts, adds it to an array on button click, and sets the array as the adapter for the list view to display the student information.

Uploaded by

MUSHI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MAD Lab Assignment 5

Name : Zain mushtaq


Sap ID : 70067944
Section : B
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<EditText

android:id="@+id/Name"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

android:textSize="20sp" />

<EditText

android:id="@+id/Department"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

android:textSize="20sp"/>

<EditText

android:id="@+id/Cgpa"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"
android:textSize="20sp"/>

<ListView

android:id="@+id/listview"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:dividerHeight="2dp"

android:divider="@color/teal_700"/>

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/btn"

android:text="" />

</LinearLayout>

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

<TextView xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/label"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

android:textSize="20sp"

android:textStyle="bold|italic" />
MainActivity.java
package com.example.lab3t2;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ListView;

import android.widget.TextView;

import com.example.lab3t2.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

ListView list1;

EditText Edit1, Edit2, Edit3;

TextView text1;

Button btn1 ;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

btn1 = (Button) findViewById(R.id.btn);

Edit1= (EditText) findViewById(R.id.Name);

Edit2= (EditText) findViewById(R.id.Department);

Edit3= (EditText) findViewById(R.id.Cgpa);

btn1.setOnClickListener(this);

@Override

public void onClick(View view) {

if (btn1.getId() == view.getId()) {

String [] array = new String[3];

array[0]=Edit1.getText().toString();

array[1]=Edit2.getText().toString();

array[2]=Edit3.getText().toString();

list1 = (ListView) findViewById(R.id.listview);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.label,


array);

list1.setAdapter(adapter);

You might also like