SlideShare a Scribd company logo
Android ListView Tutorial
By - Javatechig.com
Android ListView Tutorial
Table of Contents
1. What is Adapter?
2. Building ListView using ArrayAdapter
3. Building ListView using Custom Adapter
3.1. Create your custom row layout
3.2. Writing a custom adapter
3.3. Putting it all together
3.4. Output
4. Customizing ListView
4.1. Change ListView selection colour in Android
5. How to change the divider color in the ListView?
5.1. Changing ListView divider color and height
5.2. Using a drawable for ListView divider
5.3. Changing ListView divider color pragmatically
6. References
This post will walk you through Android ListView Tutorial for building simple and customized ListView using
different Android adapters.
List is one of the most common UI patterns, which is being used extensively to display the collection of data elements
in rows. In android ListView is a view group that displays a list of scrollable items. The list items are automatically
inserted to the list using an Adapter that pulls content from a source such as an array.
1. What is Adapter?
Adapter is basically bridge between UI components and the data source that fill data into UI Component. Adapter is
used to supply the data to like spinner, list view, grid view etc. For example, we can create a list view from xml layout
without data, and using adapter we can supply data sets to list view.
If you look at the above images you will certainly get an idea of list view. This kind of customizable list views can be
done using an adapter.
2. Building ListView using ArrayAdapter
This is the simplest way we can create a simple default styled list view from array of elements. To do this there are
three things to concentrate,
1. Find out what data you want to display in list: For our example, I am considered taking a static array of
strings. But for complex scenarios it can be a response from server, or data fetched from database.
2. Declare the list view object in your xml layout: ListView is the user interface element we are using to
represent data to user. So in my example, the layout contains a list view. Make sure you provide an appropriate
id.
3. Now finally, feed the list view with the data sets: For this we use adapters. We can always customize our
adapter, but for to start let’s make it simple. I am using Array adapter class available in android.
Here is how my layout file looks like
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ListActivity" >
<ListView
android:id="@+id/months_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
ListActivity.java
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.javatechig.droid.ui;
import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListActivity extends Activity {
// Initialize the array
String[] monthsArray = { "JAN", "FEB", "MAR", "APR", "MAY", "JUNE",
"JULY",
"AUG", "SEPT", "OCT", "NOV", "DEC" };
// Declare the UI components
private ListView monthsListView;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
private ArrayAdapter arrayAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
// Initialize the UI components
monthsListView = (ListView) findViewById(R.id.months_list);
// For this moment, you have ListView where you can display a list.
// But how can we put this data set to the list?
// This is where you need an Adapter
// context - The current context.
// resource - The resource ID for a layout file containing a layout
// to use when instantiating views.
// From the third parameter, you plugged the data set to adapter
arrayAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, monthsArray);
// By using setAdapter method, you plugged the ListView with
adapter
monthsListView.setAdapter(arrayAdapter);
}
}
Output of the above code is
3. Building ListView using Custom Adapter
If you have followed my previous example, then you are ready with a simple list which using ArrayAdapter. Now it’s
the time to create something fancy. In this section of tutorial, you will find steps to customize a list using custom
adapters.
In this above example I am displaying a new list items. Below is my NewsItem object
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class NewsItem {
private String headline;
private String reporterName;
private String date;
public String getHeadline() {
return headline;
}
public void setHeadline(String headline) {
this.headline = headline;
}
public String getReporterName() {
return reporterName;
}
public void setReporterName(String reporterName) {
this.reporterName = reporterName;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public String toString() {
return "[ headline=" + headline + ", reporter Name=" +
reporterName + " , date=" + date + "]";
}
}
3.1. Create your custom row layout
I have created a simple layout as shown in the image below, which holds news headline, reported name and date.
list_row_layout.xml
?
1
2
3
4
5
6
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:orientation="horizontal"
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
android:padding="5dip" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="@+id/reporter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_marginTop="5dip"
android:text=""
android:textColor="#343434"
android:textSize="12sp" />
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/reporter"
android:layout_alignBottom="@+id/reporter"
android:layout_alignParentRight="true"
android:text=""
android:textColor="#343434"
android:textSize="12sp" />
</RelativeLayout>
3.2. Writing a custom adapter
CustomListAdapter.java
?
1
2
3
4
5
6
7
8
9
10
11
public class CustomListAdapter extends BaseAdapter {
private ArrayList listData;
private LayoutInflater layoutInflater;
public CustomListAdapter(Context context, ArrayList listData) {
this.listData = listData;
layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_row_layout,
null);
holder = new ViewHolder();
holder.headlineView = (TextView)
convertView.findViewById(R.id.title);
holder.reporterNameView = (TextView)
convertView.findViewById(R.id.reporter);
holder.reportedDateView = (TextView)
convertView.findViewById(R.id.date);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.headlineView.setText(listData.get(position).getHeadline());
holder.reporterNameView.setText("By, " +
listData.get(position).getReporterName());
holder.reportedDateView.setText(listData.get(position).getDate());
return convertView;
}
static class ViewHolder {
TextView headlineView;
TextView reporterNameView;
TextView reportedDateView;
}
}
3.3. Putting it all together
Now we are ready with adapter and layout. Let’s put all of them together and build a custom list.
activity_main.xml : This is my main activity layout. For making this example simpler, I just have a ListView inside a
LinearLayout.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/custom_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</LinearLayout>
Here my activity class MainActivity.java where I am initializing list view and adapter
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList image_details = getListData();
final ListView lv1 = (ListView) findViewById(R.id.custom_list);
lv1.setAdapter(new CustomListAdapter(this, image_details));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long
id) {
Object o = lv1.getItemAtPosition(position);
NewsItem newsData = (NewsItem) o;
Toast.makeText(MainActivity.this, "Selected :" + " " + newsData,
Toast.LENGTH_LONG).show();
}
});
}
private ArrayList getListData() {
ArrayList results = new ArrayList();
NewsItem newsData = new NewsItem();
newsData.setHeadline("Dance of Democracy");
newsData.setReporterName("Pankaj Gupta");
newsData.setDate("May 26, 2013, 13:35");
results.add(newsData);
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
newsData = new NewsItem();
newsData.setHeadline("Major Naxal attacks in the past");
newsData.setReporterName("Pankaj Gupta");
newsData.setDate("May 26, 2013, 13:35");
results.add(newsData);
newsData = new NewsItem();
newsData.setHeadline("BCCI suspends Gurunath pending inquiry ");
newsData.setReporterName("Rajiv Chandan");
newsData.setDate("May 26, 2013, 13:35");
results.add(newsData);
newsData = new NewsItem();
newsData.setHeadline("Life convict can`t claim freedom after 14 yrs:
SC");
newsData.setReporterName("Pankaj Gupta");
newsData.setDate("May 26, 2013, 13:35");
results.add(newsData);
newsData = new NewsItem();
newsData.setHeadline("Indian Army refuses to share info on soldiers
mutilated at LoC");
newsData.setReporterName("Pankaj Gupta");
newsData.setDate("May 26, 2013, 13:35");
results.add(newsData);
newsData = new NewsItem();
newsData.setHeadline("French soldier stabbed; link to Woolwich attack
being probed");
newsData.setReporterName("Sudeep Nanda");
newsData.setDate("May 26, 2013, 13:35");
results.add(newsData);
return results;
}
}
3.4. Output
4. Customizing ListView
Read More from JAVATECHIG.COM

More Related Content

What's hot

DynamicRecord Presentation
DynamicRecord PresentationDynamicRecord Presentation
DynamicRecord Presentation
linoj
 
Has Many And Belongs To Many
Has Many And Belongs To ManyHas Many And Belongs To Many
Has Many And Belongs To Many
guest80d303
 
Android Ui
Android UiAndroid Ui
Android Ui
Jetti Chowdary
 
Android ListView and Custom ListView
Android ListView and Custom ListView Android ListView and Custom ListView
Android ListView and Custom ListView
Sourabh Sahu
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themes
Sourabh Sahu
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
vishal choudhary
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
Paul Graham
 
Ember.js Self Defining Apps
Ember.js Self Defining AppsEmber.js Self Defining Apps
Ember.js Self Defining Apps
Oli Griffiths
 
Android UI
Android UI Android UI
Android UI
mailalamin
 
Salesforce meetup | Custom document generation
Salesforce meetup | Custom document generationSalesforce meetup | Custom document generation
Salesforce meetup | Custom document generation
Accenture Hungary
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web Component
Accenture Hungary
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
Tâm
 
EAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV ModelEAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV Model
Khoa Truong Dinh
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
Madhavendra Dutt
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
Kostyantyn Stepanyuk
 
Android Layout
Android LayoutAndroid Layout
Android Layout
mcanotes
 
Basic Android Layout
Basic Android LayoutBasic Android Layout
Basic Android Layout
Bayu Firmawan Paoh
 
form view
form viewform view
form view
AbiMurugan2
 
as400 built in function-list
as400 built in function-listas400 built in function-list
as400 built in function-list
aminem_mp
 

What's hot (19)

DynamicRecord Presentation
DynamicRecord PresentationDynamicRecord Presentation
DynamicRecord Presentation
 
Has Many And Belongs To Many
Has Many And Belongs To ManyHas Many And Belongs To Many
Has Many And Belongs To Many
 
Android Ui
Android UiAndroid Ui
Android Ui
 
Android ListView and Custom ListView
Android ListView and Custom ListView Android ListView and Custom ListView
Android ListView and Custom ListView
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themes
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
 
Ember.js Self Defining Apps
Ember.js Self Defining AppsEmber.js Self Defining Apps
Ember.js Self Defining Apps
 
Android UI
Android UI Android UI
Android UI
 
Salesforce meetup | Custom document generation
Salesforce meetup | Custom document generationSalesforce meetup | Custom document generation
Salesforce meetup | Custom document generation
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web Component
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
 
EAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV ModelEAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV Model
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
 
Android Layout
Android LayoutAndroid Layout
Android Layout
 
Basic Android Layout
Basic Android LayoutBasic Android Layout
Basic Android Layout
 
form view
form viewform view
form view
 
as400 built in function-list
as400 built in function-listas400 built in function-list
as400 built in function-list
 

Viewers also liked

H ποιητική προσφυγική ραψωδία (1922), της Παρθένας Τσοκτουρίδου
H ποιητική προσφυγική ραψωδία (1922), της Παρθένας ΤσοκτουρίδουH ποιητική προσφυγική ραψωδία (1922), της Παρθένας Τσοκτουρίδου
H ποιητική προσφυγική ραψωδία (1922), της Παρθένας Τσοκτουρίδου
pontiakilelapa ΠοντιακήΛέλαπα
 
Share file to dropbox in android example
Share file to dropbox in android exampleShare file to dropbox in android example
Share file to dropbox in android example
Javatechig Resources for Developers
 
CANNEXUS 2014 The One Way Stream Freeman Woolnough
CANNEXUS 2014 The One Way Stream Freeman WoolnoughCANNEXUS 2014 The One Way Stream Freeman Woolnough
CANNEXUS 2014 The One Way Stream Freeman Woolnough
FreemanCannexus
 
το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...
το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...
το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...
pontiakilelapa ΠοντιακήΛέλαπα
 
4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.
4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.
4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.
pontiakilelapa ΠοντιακήΛέλαπα
 
5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»
5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»
5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»
pontiakilelapa ΠοντιακήΛέλαπα
 
«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου ένα βιβλίο...
«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου   ένα βιβλίο...«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου   ένα βιβλίο...
«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου ένα βιβλίο...
pontiakilelapa ΠοντιακήΛέλαπα
 
ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...
ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...
ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...
pontiakilelapa ΠοντιακήΛέλαπα
 
Ο θάνατος της Σμύρνης (του Rene Puaux)
Ο θάνατος της Σμύρνης (του Rene Puaux)Ο θάνατος της Σμύρνης (του Rene Puaux)
Ο θάνατος της Σμύρνης (του Rene Puaux)
pontiakilelapa ΠοντιακήΛέλαπα
 
Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...
Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...
Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...
pontiakilelapa ΠοντιακήΛέλαπα
 
Ο γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας Τσοκτουρίδου
Ο γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας ΤσοκτουρίδουΟ γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας Τσοκτουρίδου
Ο γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας Τσοκτουρίδου
pontiakilelapa ΠοντιακήΛέλαπα
 
Η ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξεις
Η ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξειςΗ ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξεις
Η ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξεις
pontiakilelapa ΠοντιακήΛέλαπα
 
Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...
Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...
Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...
pontiakilelapa ΠοντιακήΛέλαπα
 
"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου
"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου
"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου
pontiakilelapa ΠοντιακήΛέλαπα
 
μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...
μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...
μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...
pontiakilelapa ΠοντιακήΛέλαπα
 
CAP Ruritan Flag Raising
CAP Ruritan Flag RaisingCAP Ruritan Flag Raising
CAP Ruritan Flag Raising
mtphillipscap
 
XpressRoam Executive Summary - PDF
XpressRoam Executive Summary - PDFXpressRoam Executive Summary - PDF
XpressRoam Executive Summary - PDF
xpressroam
 
Sencha Services
Sencha ServicesSencha Services
Sencha Services
Alok Ranjan
 
Βιογραφικό Σημείωμα Ομηριάδη Ηλία
Βιογραφικό Σημείωμα Ομηριάδη ΗλίαΒιογραφικό Σημείωμα Ομηριάδη Ηλία
Βιογραφικό Σημείωμα Ομηριάδη Ηλία
pontiakilelapa ΠοντιακήΛέλαπα
 
How to write articles for CAP
How to write articles for CAPHow to write articles for CAP
How to write articles for CAP
mtphillipscap
 

Viewers also liked (20)

H ποιητική προσφυγική ραψωδία (1922), της Παρθένας Τσοκτουρίδου
H ποιητική προσφυγική ραψωδία (1922), της Παρθένας ΤσοκτουρίδουH ποιητική προσφυγική ραψωδία (1922), της Παρθένας Τσοκτουρίδου
H ποιητική προσφυγική ραψωδία (1922), της Παρθένας Τσοκτουρίδου
 
Share file to dropbox in android example
Share file to dropbox in android exampleShare file to dropbox in android example
Share file to dropbox in android example
 
CANNEXUS 2014 The One Way Stream Freeman Woolnough
CANNEXUS 2014 The One Way Stream Freeman WoolnoughCANNEXUS 2014 The One Way Stream Freeman Woolnough
CANNEXUS 2014 The One Way Stream Freeman Woolnough
 
το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...
το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...
το τροπάριο του αγίου γεωργίου (απόσπασμα από το βιβλίο «η καμπάνα του πόντου...
 
4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.
4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.
4ο αντάμωμα ελληνικών παραδόσεων 2015, απολογισμός.
 
5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»
5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»
5o Αντάμωμα Ελληνικών Παραδόσεων «Ο Χορός ειναι Ζωή»
 
«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου ένα βιβλίο...
«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου   ένα βιβλίο...«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου   ένα βιβλίο...
«Οι πατρογονικές ρίζες των Κμνηνιωτών» της Παρθένας Τσοκτουρίδου ένα βιβλίο...
 
ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...
ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...
ο παρευξείνιος ελληνισμός κατά τον 19ο και 20ο αιώνα και ο κίνδυνος υπερίσχυσ...
 
Ο θάνατος της Σμύρνης (του Rene Puaux)
Ο θάνατος της Σμύρνης (του Rene Puaux)Ο θάνατος της Σμύρνης (του Rene Puaux)
Ο θάνατος της Σμύρνης (του Rene Puaux)
 
Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...
Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...
Η αφήγηση του κυρ-Νικόλα (Απόσπασμα από το βιβλίο «Η καμπάνα του Πόντου χτυπά...
 
Ο γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας Τσοκτουρίδου
Ο γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας ΤσοκτουρίδουΟ γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας Τσοκτουρίδου
Ο γάμος, Απόσπασμα από το βιβλίο η καμπάνα του πόντου, της Παρθένας Τσοκτουρίδου
 
Η ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξεις
Η ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξειςΗ ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξεις
Η ποντιακή διάλεκτος του Γ. Σαββαντίδη με ορισμένες λέξεις
 
Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...
Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...
Προετοιμασία γάμου, (Απόσπασμα από το βιβλίο: «Η καμπάνα του Πόντου χτυπάει σ...
 
"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου
"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου
"Το χρέος" της συγγραφέως Γιώτας Τσαρμοπούλου
 
μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...
μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...
μια παλιά συνέντευξη της Παρθένας Τσοκτουρίδου από τον Κομνηνιώτη πρόσφυγα Νι...
 
CAP Ruritan Flag Raising
CAP Ruritan Flag RaisingCAP Ruritan Flag Raising
CAP Ruritan Flag Raising
 
XpressRoam Executive Summary - PDF
XpressRoam Executive Summary - PDFXpressRoam Executive Summary - PDF
XpressRoam Executive Summary - PDF
 
Sencha Services
Sencha ServicesSencha Services
Sencha Services
 
Βιογραφικό Σημείωμα Ομηριάδη Ηλία
Βιογραφικό Σημείωμα Ομηριάδη ΗλίαΒιογραφικό Σημείωμα Ομηριάδη Ηλία
Βιογραφικό Σημείωμα Ομηριάδη Ηλία
 
How to write articles for CAP
How to write articles for CAPHow to write articles for CAP
How to write articles for CAP
 

Similar to Android list view tutorial by Javatechig

Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Lab2-android
Lab2-androidLab2-android
Lab2-android
Lilia Sfaxi
 
List Views
List ViewsList Views
List Views
Ahsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Day 5 android app code advancement
Day 5  android app code advancementDay 5  android app code advancement
Day 5 android app code advancement
FatimaYousif11
 
Grid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdfGrid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdf
deepua8
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
Gil Irizarry
 
Android Training Session 1
Android Training Session 1Android Training Session 1
Android Training Session 1
Shanmugapriya D
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbit
CarWash1
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
Hello Android
Hello AndroidHello Android
Hello Android
Trong Dinh
 
Android App To Display Employee Details
Android App To Display Employee DetailsAndroid App To Display Employee Details
Android App To Display Employee Details
Saikrishna Tanguturu
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
Vivek Bhusal
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
Vivek Bhusal
 
Android practice of layout in application-chapter6
Android practice of layout in application-chapter6Android practice of layout in application-chapter6
Android practice of layout in application-chapter6
Dr. Ramkumar Lakshminarayanan
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
Padma shree. T
 
Android resources in android-chapter9
Android resources in android-chapter9Android resources in android-chapter9
Android resources in android-chapter9
Dr. Ramkumar Lakshminarayanan
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
Padma shree. T
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
InnovationM
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
Ahsanul Karim
 

Similar to Android list view tutorial by Javatechig (20)

Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Lab2-android
Lab2-androidLab2-android
Lab2-android
 
List Views
List ViewsList Views
List Views
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Day 5 android app code advancement
Day 5  android app code advancementDay 5  android app code advancement
Day 5 android app code advancement
 
Grid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdfGrid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdf
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Android Training Session 1
Android Training Session 1Android Training Session 1
Android Training Session 1
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbit
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Android App To Display Employee Details
Android App To Display Employee DetailsAndroid App To Display Employee Details
Android App To Display Employee Details
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
 
Android practice of layout in application-chapter6
Android practice of layout in application-chapter6Android practice of layout in application-chapter6
Android practice of layout in application-chapter6
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
 
Android resources in android-chapter9
Android resources in android-chapter9Android resources in android-chapter9
Android resources in android-chapter9
 
ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON ACADGILD:: ANDROID LESSON
ACADGILD:: ANDROID LESSON
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
 

Recently uploaded

The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 

Android list view tutorial by Javatechig

  • 1. Android ListView Tutorial By - Javatechig.com
  • 2. Android ListView Tutorial Table of Contents 1. What is Adapter? 2. Building ListView using ArrayAdapter 3. Building ListView using Custom Adapter 3.1. Create your custom row layout 3.2. Writing a custom adapter 3.3. Putting it all together 3.4. Output 4. Customizing ListView 4.1. Change ListView selection colour in Android 5. How to change the divider color in the ListView? 5.1. Changing ListView divider color and height 5.2. Using a drawable for ListView divider 5.3. Changing ListView divider color pragmatically 6. References This post will walk you through Android ListView Tutorial for building simple and customized ListView using different Android adapters. List is one of the most common UI patterns, which is being used extensively to display the collection of data elements in rows. In android ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array. 1. What is Adapter? Adapter is basically bridge between UI components and the data source that fill data into UI Component. Adapter is used to supply the data to like spinner, list view, grid view etc. For example, we can create a list view from xml layout without data, and using adapter we can supply data sets to list view.
  • 3. If you look at the above images you will certainly get an idea of list view. This kind of customizable list views can be done using an adapter. 2. Building ListView using ArrayAdapter This is the simplest way we can create a simple default styled list view from array of elements. To do this there are three things to concentrate, 1. Find out what data you want to display in list: For our example, I am considered taking a static array of strings. But for complex scenarios it can be a response from server, or data fetched from database. 2. Declare the list view object in your xml layout: ListView is the user interface element we are using to represent data to user. So in my example, the layout contains a list view. Make sure you provide an appropriate id. 3. Now finally, feed the list view with the data sets: For this we use adapters. We can always customize our adapter, but for to start let’s make it simple. I am using Array adapter class available in android. Here is how my layout file looks like ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".ListActivity" > <ListView android:id="@+id/months_list" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> ListActivity.java ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 package com.javatechig.droid.ui; import android.os.Bundle; import android.app.Activity; import android.widget.ArrayAdapter; import android.widget.ListView; public class ListActivity extends Activity { // Initialize the array String[] monthsArray = { "JAN", "FEB", "MAR", "APR", "MAY", "JUNE", "JULY", "AUG", "SEPT", "OCT", "NOV", "DEC" }; // Declare the UI components private ListView monthsListView;
  • 4. 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 private ArrayAdapter arrayAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); // Initialize the UI components monthsListView = (ListView) findViewById(R.id.months_list); // For this moment, you have ListView where you can display a list. // But how can we put this data set to the list? // This is where you need an Adapter // context - The current context. // resource - The resource ID for a layout file containing a layout // to use when instantiating views. // From the third parameter, you plugged the data set to adapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, monthsArray); // By using setAdapter method, you plugged the ListView with adapter monthsListView.setAdapter(arrayAdapter); } } Output of the above code is 3. Building ListView using Custom Adapter If you have followed my previous example, then you are ready with a simple list which using ArrayAdapter. Now it’s the time to create something fancy. In this section of tutorial, you will find steps to customize a list using custom adapters.
  • 5. In this above example I am displaying a new list items. Below is my NewsItem object ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 public class NewsItem { private String headline; private String reporterName; private String date; public String getHeadline() { return headline; } public void setHeadline(String headline) { this.headline = headline; } public String getReporterName() { return reporterName; } public void setReporterName(String reporterName) { this.reporterName = reporterName; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } @Override public String toString() { return "[ headline=" + headline + ", reporter Name=" + reporterName + " , date=" + date + "]"; } } 3.1. Create your custom row layout I have created a simple layout as shown in the image below, which holds news headline, reported name and date. list_row_layout.xml ? 1 2 3 4 5 6 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="50dp" android:orientation="horizontal"
  • 6. 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 android:padding="5dip" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textStyle="bold" android:typeface="sans" /> <TextView android:id="@+id/reporter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/title" android:layout_marginTop="5dip" android:text="" android:textColor="#343434" android:textSize="12sp" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/reporter" android:layout_alignBottom="@+id/reporter" android:layout_alignParentRight="true" android:text="" android:textColor="#343434" android:textSize="12sp" /> </RelativeLayout> 3.2. Writing a custom adapter CustomListAdapter.java ? 1 2 3 4 5 6 7 8 9 10 11 public class CustomListAdapter extends BaseAdapter { private ArrayList listData; private LayoutInflater layoutInflater; public CustomListAdapter(Context context, ArrayList listData) { this.listData = listData; layoutInflater = LayoutInflater.from(context); } @Override public int getCount() {
  • 7. 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 return listData.size(); } @Override public Object getItem(int position) { return listData.get(position); } @Override public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = layoutInflater.inflate(R.layout.list_row_layout, null); holder = new ViewHolder(); holder.headlineView = (TextView) convertView.findViewById(R.id.title); holder.reporterNameView = (TextView) convertView.findViewById(R.id.reporter); holder.reportedDateView = (TextView) convertView.findViewById(R.id.date); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.headlineView.setText(listData.get(position).getHeadline()); holder.reporterNameView.setText("By, " + listData.get(position).getReporterName()); holder.reportedDateView.setText(listData.get(position).getDate()); return convertView; } static class ViewHolder { TextView headlineView; TextView reporterNameView; TextView reportedDateView; } } 3.3. Putting it all together Now we are ready with adapter and layout. Let’s put all of them together and build a custom list.
  • 8. activity_main.xml : This is my main activity layout. For making this example simpler, I just have a ListView inside a LinearLayout. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/custom_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:dividerHeight="1dp" /> </LinearLayout> Here my activity class MainActivity.java where I am initializing list view and adapter ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayList image_details = getListData(); final ListView lv1 = (ListView) findViewById(R.id.custom_list); lv1.setAdapter(new CustomListAdapter(this, image_details)); lv1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { Object o = lv1.getItemAtPosition(position); NewsItem newsData = (NewsItem) o; Toast.makeText(MainActivity.this, "Selected :" + " " + newsData, Toast.LENGTH_LONG).show(); } }); } private ArrayList getListData() { ArrayList results = new ArrayList(); NewsItem newsData = new NewsItem(); newsData.setHeadline("Dance of Democracy"); newsData.setReporterName("Pankaj Gupta"); newsData.setDate("May 26, 2013, 13:35"); results.add(newsData);
  • 9. 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 newsData = new NewsItem(); newsData.setHeadline("Major Naxal attacks in the past"); newsData.setReporterName("Pankaj Gupta"); newsData.setDate("May 26, 2013, 13:35"); results.add(newsData); newsData = new NewsItem(); newsData.setHeadline("BCCI suspends Gurunath pending inquiry "); newsData.setReporterName("Rajiv Chandan"); newsData.setDate("May 26, 2013, 13:35"); results.add(newsData); newsData = new NewsItem(); newsData.setHeadline("Life convict can`t claim freedom after 14 yrs: SC"); newsData.setReporterName("Pankaj Gupta"); newsData.setDate("May 26, 2013, 13:35"); results.add(newsData); newsData = new NewsItem(); newsData.setHeadline("Indian Army refuses to share info on soldiers mutilated at LoC"); newsData.setReporterName("Pankaj Gupta"); newsData.setDate("May 26, 2013, 13:35"); results.add(newsData); newsData = new NewsItem(); newsData.setHeadline("French soldier stabbed; link to Woolwich attack being probed"); newsData.setReporterName("Sudeep Nanda"); newsData.setDate("May 26, 2013, 13:35"); results.add(newsData); return results; } } 3.4. Output
  • 10. 4. Customizing ListView Read More from JAVATECHIG.COM