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

Ex 14

The document describes an Android application that displays a list of programming languages in a ListView. It includes the XML layout file defining the ListView and the Java code to populate the list with sample data and handle item clicks by displaying a Toast notification.

Uploaded by

suyashkurunkar
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)
27 views3 pages

Ex 14

The document describes an Android application that displays a list of programming languages in a ListView. It includes the XML layout file defining the ListView and the Java code to populate the list with sample data and handle item clicks by displaying a Toast notification.

Uploaded by

suyashkurunkar
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/ 3

Ex14_1

Xml file:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical">

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

Java file:-

package com.example.ex14_1;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


String lang[] = {"Android", "Java", "Php", "Hadoop", "Sap",
"Python", "Ajax", "C++", "Ruby", "Rails", ".Net"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView lv =(ListView) findViewById(R.id.lv);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,lang);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View
view, int position, long id) {
Toast.makeText(MainActivity.this,
((TextView)view).getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
output:-

Ex14_3

Xml file:-
<?xml version= "1.0" encoding= "utf-8" ?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
tools:context=".MainActivity">
</GridView>

Java file:-
package com.example.ex14_3;
import android.os.Bundle;

import android.widget.ArrayAdapter;
import android.widget.GridView;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
String arr[] = new String[15];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final GridView gridview =(GridView) findViewById(R.id.gv);
for (int i = 0; i < 15; i++) {
arr[i] = Integer.toString(i + 1);
}
ArrayAdapter<String> ad = new ArrayAdapter<String>(this,
R.layout.activity_listview, R.id.btn, arr);
gridview.setAdapter(ad);
}
}
output:

You might also like