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);
}
});
}
}