title: Click Listener on ListView
body: <p>I have modified this example from the SDK pages to grab all the Contact Groups from the phone and display them.  I cannot, however, figure out how to click one of them and then use the Groups._ID to do something else.  Can someone teach me how to get a click/select listener on this list?</p>
  
  <p>MyListAdapter.java</p>
  
  <pre><code>package com.example.simplelist;
  
  import android.app.ListActivity;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.Contacts.Groups;
  import android.widget.ListAdapter;
  import android.widget.SimpleCursorAdapter;
  
  public class MyListAdapter extends ListActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.custom_list_activity_view);
          Cursor mCursor = this.getContentResolver().query(Groups.CONTENT_URI, null, null, null, null);
          startManagingCursor(mCursor);
          ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item, mCursor, new String[] {Groups.NAME, Groups._ID}, new int[] {android.R.id.text1, android.R.id.text2});
          setListAdapter(adapter);
      }
  }
  </code></pre>
  
  <p>custom_list_activity_view.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:paddingLeft="8dp"
           android:paddingRight="8dp"&gt;
  
       &lt;ListView android:id="@id/android:list"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:background="#00FF00"
                 android:layout_weight="1"
                 android:drawSelectorOnTop="false" android:choiceMode="singleChoice" android:clickable="true" /&gt;
  
       &lt;TextView android:id="@id/android:empty"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:background="#FF0000"
                 android:text="No data"/&gt;
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>two_line_list_item.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical"&gt;
  
       &lt;TextView android:id="@+id/text1"
           android:textSize="16sp"
           android:textStyle="bold"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"/&gt;
  
       &lt;TextView android:id="@+id/text2"
           android:textSize="16sp"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"/&gt;
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.simplelist"
        android:versionCode="1"
        android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="3" /&gt;
  
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".MyListAdapter"
                    android:label="@string/app_name"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
      &lt;/application&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
  &lt;/manifest&gt;
  </code></pre>