0% found this document useful (0 votes)
18 views4 pages

Basic Android App with Views Tutorial

The document describes an Android application that was created with basic views like a TextView, Button, and ListView. The XML layout code and Java code is provided to build these views and populate the ListView with sample data.

Uploaded by

ujjwal singh
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)
18 views4 pages

Basic Android App with Views Tutorial

The document describes an Android application that was created with basic views like a TextView, Button, and ListView. The XML layout code and Java code is provided to build these views and populate the ListView with sample data.

Uploaded by

ujjwal singh
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

Ujjwal Singh

0801IT211090
ASSIGNMENT-03

Create application with Basic Views (Text view, Button, List View) and run on the Emulator.

CODE:

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">

<ImageView
android:id="@+id/imageView3"
android:layout_width="191dp"
android:layout_height="192dp"
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.256"
app:srcCompat="@mipmap/ic_launcher" />

<Button
android:id="@+id/button3"
android:layout_width="107dp"
android:layout_height="57dp"
android:onClick="Done"
android:text="Done"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView3"
app:layout_constraintVertical_bias="0.953" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Demo Application"
Ujjwal Singh
0801IT211090
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toTopOf="@+id/imageView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ListView
android:id="@+id/list"
android:layout_width="409dp"
android:layout_height="193dp"
app:layout_constraintBottom_toTopOf="@+id/button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView3"
app:layout_constraintVertical_bias="0.516" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA
package com.example.beginner;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

// Define the array of items


String[] items = {"Android", "Java", "XML"};

// Create an ArrayAdapter to populate the ListView


ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items);
Ujjwal Singh
0801IT211090
// Find the List by its ID
ListViewlistView = findViewById(R.id.list);

// Set the adapter for the List


listView.setAdapter(adapter);
}

// Done
public void Done(View view) {
Toast.makeText(this, "App Created", Toast.LENGTH_SHORT).show();
}
}
OUTPUT:

FUNCTIONALITY:

MainActivity.java:
• Initialize views: TextView, Button, and ListView.
• Create an array of items for the ListView.
• Set up an ArrayAdapter for the ListView.
Activity_main.xml: Contains a TextView (textView), a Button (button), and a ListView (list)
Ujjwal Singh
0801IT211090

You might also like