0% found this document useful (0 votes)
11 views2 pages

ListView GridView ImageView

The document contains an XML layout file and a Java activity class for an Android application. The layout includes a ListView, a GridView, and an ImageView, while the MainActivity initializes these views with sample data. The ListView displays a predefined array of items, and the GridView shows the English alphabet.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

ListView GridView ImageView

The document contains an XML layout file and a Java activity class for an Android application. The layout includes a ListView, a GridView, and an ImageView, while the MainActivity initializes these views with sample data. The ListView displays a predefined array of items, and the GridView shows the English alphabet.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

<ListView
android:id="@+id/sample_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<GridView
android:id="@+id/gridview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit"/>

<ImageView
android:id="@+id/full_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/android_logo" />

</LinearLayout>

MainActivity.java

package in.msbte.controls_exam_ques;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {

String[] sampleArray = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
static final String[] alphabets = {
"A", "B", "C", "D", "E",
"F", "G", "H", "I", "J",
"K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"
};

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

ListView listView = findViewById(R.id.sample_list);


GridView gridView = findViewById(R.id.gridview1);

listView.setAdapter(new ArrayAdapter<>(this, R.layout.simple_item,


sampleArray));
gridView.setAdapter(new ArrayAdapter<>(this, R.layout.simple_item,
alphabets));
}
}

You might also like