title: Set onClick listener on extended Listview
body: <blockquote>
    <p>I am working on Email application. I am able to get Inbox Mail in
    listview. Now I have to click the list and open that particular email
    in different activity. But I don't understand  how to set Onclick in
    listview.</p>
    
    <p>Here is my code of inbox-mail activity.</p>
  </blockquote>
  
  <pre><code>  public class InboxActivity extends ListActivity {
      // Progress Dialog
      private ProgressDialog pDialog;
  
      public static String uid;
      public static String uri;
      SharedPreferences myPriferene2;
      // Creating JSON Parser object
      JSONParser jsonParser = new JSONParser();
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; inboxList;
  
      // products JSONArray
      JSONArray inbox = null;
  
      // Inbox JSON url
      private static final String INBOX_URL = "http://xyz/webservice/inboxlist.php";
  
      // ALL JSON node names
      private static final String TAG_MESSAGES = "messages";
      private static final String TAG_ID = "id";
      private static final String TAG_FROM = "from";
      private static final String TAG_EMAIL = "email";
      private static final String TAG_SUBJECT = "subject";
      //private static final String TAG_DATE = "date";
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.inbox_list);
  
          // Hashmap for ListView
          inboxList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  
  
          myPriferene2=getSharedPreferences("my_key_share", MODE_PRIVATE);
  
          uri = myPriferene2.getString("uid","");
  
  
          String uid =uri.toString();
  
          Log.d("helloooooo",uid);
          // Loading INBOX in Background Thread
          new LoadInbox().execute(uid);
      }
  
      /**
       * Background Async Task to Load all INBOX messages by making HTTP Request
       * */
      class LoadInbox extends AsyncTask&lt;String, String, String&gt; {
  
          /**
           * Before starting background thread Show Progress Dialog
           * */
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(InboxActivity.this);
              pDialog.setMessage("Loading Inbox ...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(false);
              pDialog.show();
          }
  
          /**
           * getting Inbox JSON
           * */
          protected String doInBackground(String... args) {
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
  
              params.add(new BasicNameValuePair("uid", args[0]));
  
              // getting JSON string from URL
              JSONObject json = jsonParser.makeHttpRequest(INBOX_URL, "GET",params);
  
              // Check your log cat for JSON reponse
              Log.d("Inbox JSON: ", json.toString());
  
              try {
                  inbox = json.getJSONArray(TAG_MESSAGES);
                  // looping through All messages
                  for (int i = 0; i &lt; inbox.length(); i++) {
                      JSONObject c = inbox.getJSONObject(i);
  
                      // Storing each json item in variable
                      String id = c.getString(TAG_ID);
                      String from = c.getString(TAG_FROM);
                      String subject = c.getString(TAG_SUBJECT);
                      //String date = c.getString(TAG_DATE);
  
                      // creating new HashMap
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      map.put(TAG_ID, id);
                      map.put(TAG_FROM, from);
                      map.put(TAG_SUBJECT, subject);
                      //map.put(TAG_DATE, date);
  
                      // adding HashList to ArrayList
                      inboxList.add(map);
                  }
  
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
              return null;
          }
  
          /**
           * After completing background task Dismiss the progress dialog
           * **/
          protected void onPostExecute(String file_url) {
              // dismiss the dialog after getting all products
              pDialog.dismiss();
              // updating UI from Background Thread
              runOnUiThread(new Runnable() {
                  public void run() {
                      /**
                       * Updating parsed JSON data into ListView
                       * */
                      ListAdapter adapter = new SimpleAdapter(
                              InboxActivity.this, inboxList,
                              //R.layout.inbox_list_item, new String[] { TAG_FROM, TAG_SUBJECT, TAG_DATE },
                              R.layout.inbox_list_item, new String[] { TAG_FROM, TAG_SUBJECT,TAG_ID},
                              //new int[] { R.id.from, R.id.subject, R.id.emailID});
  
                      new int[] { R.id.from, R.id.subject , R.id.date});
                      // updating listview
                      setListAdapter(adapter);
                  }
              });
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>here is my ListActivity</p>
  </blockquote>
  
  <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="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <blockquote>
    <p>this is my list item activity</p>
  </blockquote>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#746555"
      android:orientation="vertical" &gt;
  
  
      &lt;TextView
          android:id="@+id/from"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:paddingTop="8dip"
          android:paddingLeft="8dip"
          android:paddingBottom="4dip"
          android:textSize="20dip"
          android:textStyle="bold" /&gt;
  
  
      &lt;TextView android:id="@+id/subject"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:paddingLeft="8dip"
          android:paddingBottom="6dip"
          android:textSize="15dip"
          android:layout_below="@id/from"/&gt;
  
  
      &lt;TextView android:id="@+id/date"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:padding="8dip"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>