Android Simple ListVIew

Android ListView Lets you display Views in Vertical Scrollable List , In this example you will see list of planet names displayed in listview



1. ListActivity


file:-Simplelist.java
package com.example.com.pavan.simple_listview;
import android.os.Bundle;
import android.app.ListActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Simplelist extends ListActivity {

 String[] planets = new String[] { "Sun", "Mercury", "Venus", "Earth",
   "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  ArrayAdapter<string> aa = new ArrayAdapter<string>(this,
    android.R.layout.simple_list_item_1, planets);
  setListAdapter(aa);

 }

 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
  // TODO Auto-generated method stub
  super.onListItemClick(l, v, position, id);
  Toast.makeText(Simplelist.this, "you clicked  " + planets[position],
    Toast.LENGTH_SHORT).show();
 }
}

2. RUN





4 comments:

M Kumar said...

Good example...........................

Naveen said...

Good Example!!

azeem hussain said...

Amazing tutorials , Please suggest any best book for android based on android studio

How SimpleAdapter Binds Hashmap Data to items of ListView - TutorialsBuzz said...

[…] ListView With ArrayAdapter . […]

Post a Comment