0% found this document useful (0 votes)
25 views5 pages

Pra 14 EX

The document contains two Android application examples. The first example demonstrates a ListView displaying a list of programming languages, where clicking an item shows a Toast message with the selected language. The second example features an ImageView and a Button that changes the displayed image when the button is clicked, cycling through three images.

Uploaded by

sammedmohare465
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)
25 views5 pages

Pra 14 EX

The document contains two Android application examples. The first example demonstrates a ListView displaying a list of programming languages, where clicking an item shows a Toast message with the selected language. The second example features an ImageView and a Button that changes the displayed image when the button is clicked, cycling through three images.

Uploaded by

sammedmohare465
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

Pra:14

Ex:Q.1

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


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

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

</RelativeLayout>

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {

String programming_langs[] = {"Android", "Java", "Php", "Hadoop", "Sap", "Python",


"Ajax", "C++", "Ruby", "Rails", ".Net"};
ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);
setContentView([Link].activity_main);

listView = findViewById([Link].list_view);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,


[Link].simple_list_item_1, programming_langs);
[Link](adapter);
[Link](new [Link]() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
[Link]([Link], ((TextView)view).getText().toString(),
Toast.LENGTH_SHORT).show();
}
});
}
}

Q.2

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

<RelativeLayout xmlns:android="[Link]

xmlns:tools="[Link]

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="[Link]">

<ImageView
android:layout_width="200dp"

android:layout_height="200dp"

android:layout_centerHorizontal="true"

android:id="@+id/img1"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/img1"

android:layout_centerHorizontal="true"

android:text="Change Image"

android:id="@+id/button"/>

</RelativeLayout>

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];
public class MainActivity extends AppCompatActivity {

Button b1;

ImageView iv;

boolean flag;

int images[]={[Link].ic1,[Link].ic2,[Link].ic3};

int i=0;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

iv=(ImageView) findViewById([Link].img1);

b1=(Button) findViewById([Link]);

flag=true;

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link](images[i]);

i++;
if(i==3)

i=0;

});

You might also like