title: Adding listener to ListView
body: <p>I've created a ListView from an SQLite database but am stuck on how to add a listener to each ListView item so that when an item is clicked I can display another page with more information on that item. The database is just a sample. Any help would be appreciated.</p>
  
  <pre><code>public class Database extends ListActivity {
  
  private final String SAMPLE_DB_NAME = "myFriendsDb";
  //private final String SAMPLE_TABLE_NAME = "friends";
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();
      SQLiteDatabase db = null;
  
      try {
          db =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
  
          db.execSQL("CREATE TABLE IF NOT EXISTS people" +
                  " (LastName VARCHAR, FirstName VARCHAR," +
                  " Country VARCHAR, Age INT(3));");
  
          db.execSQL("INSERT INTO people" +
                  " Values ('Jones','Bob','UK',30);");
          db.execSQL("INSERT INTO people" +
                  " Values ('Smith','John','UK',40);");
          db.execSQL("INSERT INTO people" +
                  " Values ('Thompson','James','UK',50);");
  
          Cursor c = db.rawQuery("SELECT FirstName, LastName FROM people", null);
  
          if (c != null ) {
              if  (c.moveToFirst()) {
                  do {
                      String firstName = c.getString(c.getColumnIndex("FirstName"));
                      String lastName = c.getString(c.getColumnIndex("LastName"));
                      results.add("" + firstName + " " + lastName);
                  }while (c.moveToNext());
              } 
          }
  
          this.setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,results));
  
      } catch (SQLiteException se ) {
          Log.e(getClass().getSimpleName(), "Could not create or Open the database");
      } finally {
          if (db != null) 
              db.execSQL("DELETE FROM people");
              db.close();
      }
  }
  </code></pre>
  
  <p>}</p>