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

IT402 17IT416 File

The document describes an Android app that contains: 1) A list view to display a list of colleges in the top half of the screen, with each item showing the college name and type. 2) Edit text fields below to enter a new college name and type. 3) A button to add the input details to the list view when clicked. The code provided implements this functionality using an array adapter, edit texts, list view and button click listener.

Uploaded by

jayu ahir
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)
28 views

IT402 17IT416 File

The document describes an Android app that contains: 1) A list view to display a list of colleges in the top half of the screen, with each item showing the college name and type. 2) Edit text fields below to enter a new college name and type. 3) A button to add the input details to the list view when clicked. The code provided implements this functionality using an array adapter, edit texts, list view and button click listener.

Uploaded by

jayu ahir
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/ 7

17IT416

Aim:- Create an Android App which has one activity which has list of College-in format “ College Name:
College Type(Engineering, Pharmacy, etc)” in ListView in top half of the Screen. In Bottom half get
details of College like name and Type of (EditText).On Pressing a Button called “Add To List” the
details should be added in the Listview displayed in top half of the screen

Code:-

MainActivity.java

package com.example.exam;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ListView;

public class MainActivity extends AppCompatActivity {

private Button addToList;

private EditText Name,Type;

private ListView list;

private ArrayAdapter<String> adapter;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

addToList = (Button)findViewById(R.id.button);

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

Type = (EditText)findViewById(R.id.editTextTextPersonName2);

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

list.setBackgroundColor(Color.GREEN);

adapter = new ArrayAdapter<String>(getApplicationContext(),


android.R.layout.simple_spinner_item);

list.setAdapter(adapter);

addToList.setOnClickListener(new View.OnClickListener() {

public void onClick(View v)

if( !( Name.getText().equals("") || Type.getText().equals("") ) ){

adapter.add(Name.getText()+" : "+ Type.getText());

});

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

<androidx.constraintlayout.widget.ConstraintLayout
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"

tools:context=".MainActivity">

<ListView

android:id="@+id/list1"

android:layout_width="339dp"

android:layout_height="378dp"

android:background="#00A31D1D"

android:backgroundTint="#00C23838"

android:backgroundTintMode="add"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.571"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.01"></ListView>

<EditText

android:id="@+id/editTextTextPersonName"

android:layout_width="135dp"
android:layout_height="45dp"

android:ems="10"

android:inputType="textPersonName"

android:text=""

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.219"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.781" />

<EditText

android:id="@+id/editTextTextPersonName2"

android:layout_width="135dp"

android:layout_height="45dp"

android:ems="10"

android:inputType="textPersonName"

android:text=""

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.873"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.781" />
<TextView

android:id="@+id/textView3"

android:layout_width="132dp"

android:layout_height="39dp"

android:layout_marginBottom="20dp"

android:gravity="center"

android:text="C_Name"

android:textSize="25dp"

app:layout_constraintBottom_toTopOf="@+id/editTextTextPersonName"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.216"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="1.0" />

<TextView

android:id="@+id/textView"

android:layout_width="132dp"

android:layout_height="39dp"

android:layout_marginBottom="20dp"

android:gravity="center"

android:text="C_Type"

android:textSize="25dp"

app:layout_constraintBottom_toTopOf="@+id/editTextTextPersonName"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.863"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="1.0" />

<Button

android:id="@+id/button"

android:layout_width="124dp"

android:layout_height="52dp"

android:text="Add to List"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.91" />

</androidx.constraintlayout.widget.ConstraintLayout>

Output:-

You might also like