0% found this document useful (0 votes)
8 views3 pages

Exp14 Remaining

The document contains XML layout files for an Android application, specifically for 'activity_main.xml' and 'gridview.xml', which define a GridView and a Button. It also includes a Java class 'MainActivity' that sets up the GridView with an ArrayAdapter and handles button clicks to change an ImageView's source. The code demonstrates basic Android UI components and their interactions in an app context.

Uploaded by

dikshabhandare43
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)
8 views3 pages

Exp14 Remaining

The document contains XML layout files for an Android application, specifically for 'activity_main.xml' and 'gridview.xml', which define a GridView and a Button. It also includes a Java class 'MainActivity' that sets up the GridView with an ArrayAdapter and handles button clicks to change an ImageView's source. The code demonstrates basic Android UI components and their interactions in an app context.

Uploaded by

dikshabhandare43
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

Activity_main.

XML arr[i]="Number"+i;

<?xml version="1.0" encoding="utf-8"?> }


<LinearLayout ArrayAdapter ad=new
xmlns:android="http://schemas.android.com/apk/re ArrayAdapter(MainActivity.this,R.layout.gridview,
s/android" R.id.button,arr);
xmlns:app="http://schemas.android.com/apk/res- gridview.setAdapter(ad);
auto" }
xmlns:tools="http://schemas.android.com/tools" }
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MissingClass">
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent" OUTPUT:
android:layout_height="match_parent"
android:numColumns="3"
/>
</LinearLayout>

Gridview.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/re
s/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
MainActivity.Java
package com.example.exp14_st3;

import
androidx.appcompat.app.AppCompatActivity;
EXP_14_4
import android.annotation.SuppressLint;
CODE:-
import android.os.Bundle;
import android.widget.ArrayAdapter; <?xml version="1.0" encoding="utf-8"?>
import android.widget.GridView;
<LinearLayout
public class MainActivity extends
xmlns:android="http://schemas.android.com/a
AppCompatActivity {
GridView gridview; pk/res/android"
String[] arr=new String[16];
@SuppressLint("MissingInflatedId")
@Override xmlns:app="http://schemas.android.com/apk/r
protected void onCreate(Bundle es-auto"
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); xmlns:tools="http://schemas.android.com/tool
s"
gridview=findViewById(R.id.gridview);
android:layout_width="match_parent"
for(int i=0;i<arr.length;i++){
android:layout_height="match_parent" import
androidx.appcompat.app.AppCompatActivity;
android:orientation="vertical"
import android.os.Bundle;
android:padding="5dp"
import
tools:context=".MainActivity"> android.support.v4.app.RemoteActionCompat
Parcelizer;
import android.widget.Button;
import android.widget.ImageView;
import android.view.View;

<ImageView
android:id="@+id/imageview" import android.os.Bundle;

android:layout_width="match_parent"
android:layout_height="624dp"
app:srcCompat="@drawable/image_1" /> public class MainActivity extends
AppCompatActivity {
<Button
ImageView iv;
android:layout_width="200dp"
Button b;
android:layout_height="wrap_content"
int count=1;
android:layout_marginLeft="100dp"
android:text="Button"
@Override
android:textSize="30dp"
protected void onCreate(Bundle
android:textStyle="bold" savedInstanceState) {
android:id="@+id/b1"/> super.onCreate(savedInstanceState);
</LinearLayout> setContentView(R.layout.activity_main);
JAVA:
package com.example.exp_14_4; iv=(ImageView)findViewById(R.id.imagevie
w);
import android.os.Bundle;
b=(Button)findViewById(R.id.b1);
b.setOnClickListener((View v) -> {
import androidx.activity.EdgeToEdge;
if (count == 1) {
import
androidx.appcompat.app.AppCompatActivity;
iv.setImageResource(R.drawable.image_1);
import androidx.core.graphics.Insets;
count = 2;
import androidx.core.view.ViewCompat;
} else if (count == 2) {
import
androidx.core.view.WindowInsetsCompat;
iv.setImageResource(R.drawable.image_2);
count = 1;
}
});

You might also like