Android ListView is Viewgroup of that create list of scrollable item.A view that show item in a vertically  scrolling list.

Now create project with Android Simple Listview.
create row.xml file in res->layout folder of your project.


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android=""

now open your file in your project src folder. and 

public class MainActivity extends ListActivity

see here when we extending ListActivity to MainActivity then thet layout file must have ListView with id android:id=”@android:id/list”


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
    android:orientation="vertical" >
        android:layout_alignParentTop="true" >

Now using ArrayAdapter you can bind data with listview.ArrayAdapter is class that works to bind data to listview.You pass data in Constructor of this class.

private String[] INDIAN_STATE = { "Gujarat", "Andra Pradesh","Arunachal Pradesh", "Assam", "Bihar", "Chhattisgarh", "Goa","Haryana", "Himachal Pradesh", "Jammu and Kashmir", "Jharkhand","Karnataka", "Kerala", "Madya Pradesh", "Maharashtra", "Manipur", "Meghalaya", "Mizoram", "Nagaland", "Orissa", "Punjab", "Rajasthan", "Sikkim", "Tamil Nadu", "Tripura", "Uttaranchal", "Uttar Pradesh", "West Bengal" };

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.row, INDIAN_STATE);

now you just call setListAdapter to set Adapter to listview.


its display the indian state in listview and you can change your color of state name and background using row.xml file.they have textview,change its color or background.

Now,when listview is displayed its more important how to check which item clicked in listview and get selected or clicked value.there are OnItemClickListener for ListView.

but when you extends ListActivity then just ovveride onListItemClick  method.and there first parameter is listview.second is view which is row or item view.third is position of item.and last is id of row or item.

we can retrieve value of item.

protected void onListItemClick(ListView l, View v, int position, long id) {    
   super.onListItemClick(l, v, position, id);

   String str =l.getItemAtPosition(position).toString();
   Toast.makeText(MainActivity.this, str,Toast.LENGTH_SHORT).show();


now we discuss how to display listview without extending ListActivity. When we extends Activity there is no need to(not compulsory) your ListView have id android:id=”@android:id/list”. You can use your own list nameandroid:id=”@+id/mylist”

 you can get Listview using,

 ListView listView = (ListView)findViewById(;

And set Adapter and OnItemClickListener to listView.

listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> l, View v, int position,long id) {
String str = l.getItemAtPosition(position).toString();
Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();

DownLoad Full Source Code From Here
DownLoad Source Code



One comment

  • mobile access
    mobile access

    Hi great website! Does running a blog like this require a great deal of work?
    I have virtually no understanding of computer
    programming however I was hoping to start my own blog in the near future.
    Anyways, should you have any suggestions or techniques for
    new blog owners please share. I understand this is off topic nevertheless
    I just needed to ask. Appreciate it!

Leave a Reply

Your email address will not be published. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>