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

1) Program To Show List View - : Activity - Main - XML

The document describes an Android program that displays an image and button in a list view. The Activity_main.xml layout file contains an ImageView and Button widget. The MainActivity.java code gets references to these views, sets an onclick listener for the button to change the image source when clicked, and sets an onclick listener for the image to display a toast message when clicked.

Uploaded by

Rahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

1) Program To Show List View - : Activity - Main - XML

The document describes an Android program that displays an image and button in a list view. The Activity_main.xml layout file contains an ImageView and Button widget. The MainActivity.java code gets references to these views, sets an onclick listener for the button to change the image source when clicked, and sets an onclick listener for the image to display a toast message when clicked.

Uploaded by

Rahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Program to show list view -

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:src="@drawable/download1"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chage Image"
android:layout_marginLeft="100dp"
android:layout_below="@+id/imageView"
tools:layout_editor_absoluteX="138dp"
tools:layout_editor_absoluteY="321dp" />

</RelativeLayout>
MainActivity.java
package com.example.a732;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


ImageView imageView;
Button b1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView) findViewById(R.id.imageView);
b1=(Button) findViewById(R.id.button);

imageView.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
Toast.makeText(MainActivity.this,"hello i am android",
Toast.LENGTH_SHORT).show();
}
});

b1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
imageView.setImageResource(R.drawable.img1);
}
});

}
}

You might also like