Practical 14 - 1 PDF
Practical 14 - 1 PDF
Practical 14 - 1 PDF
14 : Develop a program to implement List View, Grid View, Image View and Scroll
View.
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:
<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: