0% found this document useful (0 votes)
12 views6 pages

PR 14

The document provides a practical guide to implementing various Android UI components including List View, Image View, and Scroll View. It includes XML layout files and corresponding Java code for each component, demonstrating how to create a List View with item click functionality, an Image View that changes images on button click, and a vertical Scroll View containing multiple Text Views. The examples aim to help users understand the integration and functionality of these UI elements in an Android application.

Uploaded by

karadetrupti04
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)
12 views6 pages

PR 14

The document provides a practical guide to implementing various Android UI components including List View, Image View, and Scroll View. It includes XML layout files and corresponding Java code for each component, demonstrating how to create a List View with item click functionality, an Image View that changes images on button click, and a vertical Scroll View containing multiple Text Views. The examples aim to help users understand the integration and functionality of these UI elements in an Android application.

Uploaded by

karadetrupti04
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/ 6

Practical No-14:Develop a program to implement List View,Grid View,Image

View and Scroll View

1.List View
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pr14">

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

</RelativeLayout>

Java Code
package com.example.shravani;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class pr14 extends AppCompatActivity {


ListView list;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_pr14);
list=(ListView)findViewById(R.id.lang);
String prog[]=new String[]{
"Android","Java","Php","Python","C++",".net","C","CSS","Ruby"
};
List<String> langlist=new ArrayList<String>(Arrays.asList(prog));
ArrayAdapter<String> adapter =new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,langlist);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {

Toast.makeText(getApplicationContext(),list.getItemAtPosition(position).toString(),Toa
st.LENGTH_SHORT).show();
}
});
}
}

Output
2.ImageView Change
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pr14a">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="251dp"
android:layout_x="0dp"
android:layout_y="101dp"
android:src="@drawable/img_3"/>

<Button
android:id="@+id/btn"
android:layout_width="149dp"
android:layout_height="60dp"
android:layout_x="147dp"
android:layout_y="426dp"
android:text="Change Image"/>

</AbsoluteLayout>

Java Code
package com.example.shravani;

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

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class pr14a extends AppCompatActivity {

ImageView img;
Button btn;
boolean i=true;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_pr14a);
final ImageView img = (ImageView) findViewById(R.id.imageView);
final Button btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(i){
img.setImageResource(R.drawable.img_3);
i=false;
}
else {
img.setImageResource(R.drawable.img_4);
i=true;
}
}
});

}
}
Output
3.Vertical ScrollView
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pr14b">

<ScrollView
android:layout_width="match_parent"
android:layout_height="297dp"
android:layout_x="0dp"
android:layout_y="213dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="TextView"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginTop="300dp"
android:text="TextView"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginTop="300dp"
android:text="TextView"></TextView>
</LinearLayout>
</ScrollView>

</AbsoluteLayout>

Output

You might also like