100% found this document useful (1 vote)
2K views3 pages

Practical 14 - 1 PDF

The document describes a program to implement different views in Android including list view, grid view, image view, and scroll view. It provides code snippets to display a list of items using a list view and display 15 buttons using a grid view. The list view code populates a list, sets an onItemClick listener to display a toast on click, and the grid view similarly populates and sets an onItemClick listener for the grid.

Uploaded by

Ajinkya Patil
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
100% found this document useful (1 vote)
2K views3 pages

Practical 14 - 1 PDF

The document describes a program to implement different views in Android including list view, grid view, image view, and scroll view. It provides code snippets to display a list of items using a list view and display 15 buttons using a grid view. The list view code populates a list, sets an onItemClick listener to display a toast on click, and the grid view similarly populates and sets an onItemClick listener for the grid.

Uploaded by

Ajinkya Patil
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/ 3

Practical No.

14 : Develop a program to implement List View, Grid View, Image View and Scroll
View.

Name: Ajinkya P. Patil Class: TYCM-II Roll No.: 39

1. Write a program to show the following output. Use Appropriate view for the same.

activity_main.xml Code:
<?xml version="1.0" encoding="utf-8"?> <ListView
<LinearLayout android:id="@+id/l1"
xmlns:android="http://schemas.android.com/a android:divider="@color/black"
pk/res/android" android:layout_width="match_parent"

xmlns:app="http://schemas.android.com/apk/r android:layout_height="match_parent"
es-auto"

xmlns:tools="http://schemas.android.com/too />
ls"
android:layout_width="match_parent" </LinearLayout>
android:layout_height="match_parent"

tools:context=".MainActivity">

MainActivity.java Code:

package com.example.lec3; "xyz", "tty", "def" , "efg" , "xyz", "tty"


};
import ArrayAdapter ad = new
androidx.appcompat.app.AppCompatActivity; ArrayAdapter(this,
androidx.appcompat.R.layout.support_simple_
import android.os.Bundle; spinner_dropdown_item,s1);
import android.view.View; // gv.setDividerHeight(5);
import android.widget.AdapterView;
import android.widget.ArrayAdapter; lv.setOnItemClickListener(new
import android.widget.ListView; AdapterView.OnItemClickListener() {
import android.widget.Toast; @Override
public void
public class MainActivity extends onItemClick(AdapterView<?> parent, View
AppCompatActivity { view, int position, long id) {

@Override Toast.makeText(MainActivity.this,"You have


protected void onCreate(Bundle clicked"+s1[position],Toast.LENGTH_SHORT).s
savedInstanceState) { how();
super.onCreate(savedInstanceState);
}
setContentView(R.layout.activity_main); });
ListView lv = (ListView)
findViewById(R.id.l1); lv.setAdapter(ad);
String s1[] ={"EDE", "BEC" , "PWP" }
, "WBP" , "OSY" , "MAD" , "STE" , "EST" , }
"CSS" , "CPH", "abc" , "def" , "efg" ,
Output:

2. Write a program to display 15 buttons using grid view.


activity_main.xml Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">

<GridView
android:id="@+id/g1"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
android:numColumns="3"/>
</LinearLayout>

MainActivity.java Code:

package com.example.lec4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View; ArrayAdapter ad = new
import android.widget.AdapterView; ArrayAdapter(this,
import android.widget.ArrayAdapter; androidx.appcompat.R.layout.support_simple_
import android.widget.GridView; spinner_dropdown_item,s1);
import android.widget.ListView;
import android.widget.Toast;
gv.setOnItemClickListener(new
public class MainActivity extends AdapterView.OnItemClickListener() {
AppCompatActivity { @Override
public void
@Override onItemClick(AdapterView<?> parent, View
protected void onCreate(Bundle view, int position, long id) {
savedInstanceState) {
super.onCreate(savedInstanceState); Toast.makeText(MainActivity.this,"You have
clicked:
setContentView(R.layout.activity_main); "+s1[position],Toast.LENGTH_SHORT).show();

GridView gv = (GridView) }
findViewById(R.id.g1); });
String s1[] ={"EDE", "BEC" , "PWP"
, "WBP" , "OSY" , "MAD" , "STE" , "EST" , gv.setAdapter(ad);
"CSS" , "CPH", "abc" , "def" , "efg" ,
"xyz", "tty", "def" , "efg" , "xyz", "tty" }
}; }

Output:

You might also like