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

Android List View Lab Manual

This lab manual document provides instructions on creating an Android application using a List View. It contains 3 tasks: 1. Write code for a basic List View application and display the output. Clicking an item displays a toast message with the selected item. 2. Modify the code to allow multiple list items to be selected and enable filtering. 3. Add a Strings.xml file to store the list items and modify the activity code to retrieve the items from the Strings.xml file.

Uploaded by

aws ajwa
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)
10 views6 pages

Android List View Lab Manual

This lab manual document provides instructions on creating an Android application using a List View. It contains 3 tasks: 1. Write code for a basic List View application and display the output. Clicking an item displays a toast message with the selected item. 2. Modify the code to allow multiple list items to be selected and enable filtering. 3. Add a Strings.xml file to store the list items and modify the activity code to retrieve the items from the Strings.xml file.

Uploaded by

aws ajwa
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

Lab Manual

Lab (5): List View

Visual Programming for Smart Devices lab

1 Instructor: Oraib M Alrashdan


 Objectives:
create an android application using List View.

Task 1: Try IT An application using List View .java


Write this code then show the output.
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends ListActivity {


String []
array_technology={"Android","Java","PHP","Python","C++","C#","Ruby","JavaFX","V
B","Ajax",".Net","Rails","Perl","HTML"};
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
//called when the activity is first created.
setListAdapter(new
ArrayAdapter<String>(this,[Link].simple_list_item_1,array_technology)
);

}
public void onListItemClick(ListView parent ,View v,int postion,long id)
{
[Link](this,"You have
selected"+array_technology[postion],Toast.LENGTH_SHORT).show();
}
}

Note: Click an item. A message containing the item selected is displayed.

2 Instructor: Oraib M Alrashdan


3 Instructor: Oraib M Alrashdan
Task 2: Try It who to allow multiple items in the List view to be selected
and how to enable filtering support.

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends ListActivity {


String []
array_technology={"Android","Java","PHP","Python","C++","C#","Ruby","JavaFX","V
B","Ajax",".Net","Rails","Perl","HTML"};
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
ListView listView = getListView();

[Link](ListView.CHOICE_MODE_MULTIPLE);
[Link](true);
setListAdapter(new
ArrayAdapter<String>(this,[Link].simple_list_item
_checked,array_technology));
}
public void onListItemClick(ListView parent ,View v,int postion,long id)
{
[Link](this,"You have selected
"+array_technology[postion],Toast.LENGTH_SHORT).show();
}
}

4 Instructor: Oraib M Alrashdan


5 Instructor: Oraib M Alrashdan
Task 3: using your application created earlier, add the following
[Link] file located in the res/values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello"> Hello World ,List View Activity ! </string>
<string name="app_name">List View </string>
<string-array name="array_technology">
<item>Android</item>
<item>Java</item>
<item>PHP</item>
<item>Python</item>
<item>C++</item>
<item>C#</item>
<item>Ruby</item>
<item>JavaFX</item>
<item>VB</item>
<item>Ajax</item>
<item>.Net</item>
<item>Rails</item>
<item>Perl</item>
<item>HTML</item>
</string-array>
</resources>

Modify the main [Link] file as shown below:


package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends ListActivity {


String [] array_technology;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
ListView listView = getListView();
[Link](ListView.CHOICE_MODE_MULTIPLE);
[Link](true);
array_technology =
getResources().getStringArray([Link].array_technology);
setListAdapter(new
ArrayAdapter<String>(this,[Link].simple_list_item_check
ed,array_technology));

}
public void onListItemClick(ListView parent ,View v,int postion,long id)
{
[Link](this,"You have selected
"+array_technology[postion],Toast.LENGTH_SHORT).show();
}
}

6 Instructor: Oraib M Alrashdan

You might also like