Android Simple ListVIew

By | October 3, 2012
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

  • Good example………………………

  • Good Example!!

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