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

Practical N0. 14 (All Views)

The document outlines the XML layout for an Android application, including a ScrollView containing TextViews, an ImageView, a ListView, and a GridView. It also includes the Java code for the MainActivity class, which initializes these views and sets up an ArrayAdapter with sample data. The layout is designed to display items in both a list and grid format within the app.

Uploaded by

Kolekar Yashraj
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)
16 views2 pages

Practical N0. 14 (All Views)

The document outlines the XML layout for an Android application, including a ScrollView containing TextViews, an ImageView, a ListView, and a GridView. It also includes the Java code for the MainActivity class, which initializes these views and sets up an ArrayAdapter with sample data. The layout is designed to display items in both a list and grid format within the app.

Uploaded by

Kolekar Yashraj
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/ 2

Practical N0.

14(All Views) android:numColumns="2" />

Activity_main.xml : <TextView
android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?> android:layout_height="wrap_content"
<ScrollView android:text="Image View"
android:textAlignment="center"
xmlns:android="http://schemas.android.com/a android:textSize="20sp"
pk/res/android" android:textStyle="bold" />

xmlns:app="http://schemas.android.com/apk/ <ImageView
res-auto" android:id="@+id/imageView"
android:layout_width="400dp"
xmlns:tools="http://schemas.android.com/tool android:layout_height="350dp"
s" android:layout_gravity="center"
android:layout_width="match_parent" app:srcCompat="@drawable/planting"
android:layout_height="match_parent" />
tools:context=".MainActivity">
<TextView
<LinearLayout android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Scroll View"
android:orientation="vertical" android:textAlignment="center"
android:padding="16dp"> android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent" </LinearLayout>
android:layout_height="wrap_content"
android:text="List View" </ScrollView>
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold" />

<ListView MainActivity.java :
android:id="@+id/listView" package com.example.practical14;
android:layout_width="match_parent"
android:layout_height="230dp" /> import android.os.Bundle;
import android.widget.ArrayAdapter;
<TextView import android.widget.GridView;
android:layout_width="match_parent" import android.widget.ListView;
android:layout_height="wrap_content" import
android:text="Grid View" androidx.appcompat.app.AppCompatActivity;
android:textAlignment="center"
android:textSize="20sp" public class MainActivity extends
android:textStyle="bold" /> AppCompatActivity {

<GridView @Override
android:id="@+id/gridView" protected void onCreate(Bundle
android:layout_width="match_parent" savedInstanceState) {
android:layout_height="200dp" super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Reference ListView and GridView


ListView listView =
findViewById(R.id.listView);
GridView gridView =
findViewById(R.id.gridView);

// Sample data
String[] items = {"Apple", "Banana",
"Cherry", "Date", "Grapes", "Orange"};

// Creating an ArrayAdapter for both views


ArrayAdapter<String> adapter = new
ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, items);

// Setting the adapter


listView.setAdapter(adapter);
gridView.setAdapter(adapter);
}
}

You might also like