title: How to setup the onClickListener for the imageview in the Listview
body: <p>There are a lot of discussions for this topic. But none of them work for me.
  I implemented a customized ListView with an <code>ImageView</code> in the <code>ListView</code> and the <code>ListView</code> is extended from the <code>ListFragment</code>. My ImageView is clickable so that when the user click the ImageView, the Camera activity is activated and the ImageView is updated with the image captured. The XML is as shown below</p>
  
  <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="@drawable/list_background_selector"
      android:orientation="horizontal"
      android:padding="5dip" &gt;
  
      &lt;!--  ListRow Left sied Thumbnail image --&gt;
      &lt;LinearLayout android:id="@+id/thumbnail"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="3dip"
          android:layout_alignParentLeft="true"
          android:background="@drawable/image_bg"
          android:layout_marginRight="5dip"&gt;
  
          &lt;ImageView
              android:id="@+id/list_image"
              android:layout_width="50dip"
              android:clickable="true"
              android:focusable="false"
              android:contentDescription="@string/image_view_description"
              android:layout_height="50dip"
              android:src="@drawable/icons_preview"
              /&gt;
  
      &lt;/LinearLayout&gt;  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now is I need to differentiate the user's click which is for the list item or for the ImageView. I setup <code>onListItemClick</code> that can catch user's click for the list item in the ListView, but when I click for the ImageView, it does not work. How can I detect when the user click the ImageView. My ListFragment class is as shown below.</p>
  
  <pre><code>public class MyListFragment extends ListFragment {
      private customList_Adaptor adapter;
      private static final int CAMERA_REQUEST = 0;
      private static final int RESULT_OK = 0;
      private static MyListFragmentInterface mCallback = null;
      static Context thisListFragmentContext = null;
      private String[] mListItems;
      private TrackerDBAdapter dbHelper;
      private List&lt;String&gt; listIDs;   
      public MyListFragment() {   
  
      }
  
      public MyListFragment(MyListFragmentInterface callback) {
          mCallback = callback;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view =  inflater.inflate(R.layout.my_list_fragment, container, false); 
          dbHelper = new TrackerDBAdapter(getActivity());
          dbHelper.open();
          Cursor cursor = dbHelper.fetchAllTrackerInTheList();
          mListItems = new String[dbHelper.getLastInsertedID()];
          thisListFragmentContext = getActivity();
          int i = 0;
          for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
              mListItems[i++] = cursor.getString(1);
  
          dbHelper.close();
          listIDs = new ArrayList&lt;String&gt;(); 
          listIDs = Arrays.asList(mListItems);
          adapter = new customList_Adaptor(thisListFragmentContext, R.layout.list_row, listIDs);
          ListView lv = (ListView) view.findViewById(android.R.id.list);      
          lv.setAdapter(adapter);     
  
  
  
          return view;
      }
  
      public void addNewTrackerintoListDisplay(TrackerInfo newTracker){
          mListItems = append(mListItems, newTracker.getIdnumber());      
          setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), 
                  android.R.layout.simple_list_item_1,
              mListItems));
      }
  
      @SuppressLint("NewApi")
      private String[] append(String[] mListItems2, String idnumber) {
          // TODO Auto-generated method stub
          final int N = mListItems2.length;
          mListItems2 = Arrays.copyOf(mListItems2, N + 1);
          mListItems2[N] = idnumber;
          return mListItems2;
      }
  
      @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
  
          mCallback.itemSelected(mListItems[position]);
      }
  
  
  }
  </code></pre>
  
  <p>My adapter class is as follow.</p>
  
  <pre><code>public class customList_Adaptor extends ArrayAdapter&lt;String&gt;{
  
  
      protected static final int CAMERA_REQUEST = 0;
  
      private Context context;
  
      private List&lt;String&gt; listIDs = new ArrayList&lt;String&gt;();
  
      public customList_Adaptor(Context context, int textViewResourceId,
              List&lt;String&gt; objects) {
          super(context, textViewResourceId, objects);
          this.setContext(context);
          this.listIDs = objects;
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          if(listIDs != null)
              return listIDs.size();
          else
              return 0;
      }
  
      @Override
      public String getItem(int arg0) {
          // TODO Auto-generated method stub
          if(listIDs != null)
              return listIDs.get(arg0);
          else
              return null;
      }
  
      @Override
      public long getItemId(int arg0) {
          // TODO Auto-generated method stub
          return arg0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View vi=convertView;
          ViewHolder viewHolder=new ViewHolder();
          LayoutInflater inflater = (LayoutInflater) this.getContext()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          if(vi==null){
              vi = inflater.inflate(R.layout.list_row, parent, false);
              viewHolder.id=(TextView)vi.findViewById(R.id.title);
              viewHolder.thumbnailImage=(ImageView)vi.findViewById(R.id.list_image);
              viewHolder.arrow=(ImageView)vi.findViewById(R.id.list_arrow);
              vi.setTag(viewHolder);
          }
          else
              viewHolder=(ViewHolder) vi.getTag();
  
  
  //      viewHolder.thumbnailImage.setOnClickListener(new OnClickListener(){
  //          
  //          @Override
  //          public void onClick(View arg0) {
  //              // TODO Auto-generated method stub
  //              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
  //              ((Activity)context).startActivityForResult(cameraIntent, CAMERA_REQUEST);
  //          }
  //          
  //      }); 
  
          // Setting all values in listview
          viewHolder.id.setText(listIDs.get(position));
  
          return vi;
      }
  
      public Context getContext() {
          return context;
      }
  
      public void setContext(Context context) {
          this.context = context;
      }
  
  
  }
  </code></pre>