title: Using OnItemClickListener on CheckBoxes in ListView with Adapter
body: <p>I have a row which is represented by an image, some text and a CheckBoxes. Whenever I'm trying to use the OnItemClickListener for the rows, the event won't fire up when clicking the CheckBoxes. </p>
  
  <p>I also tried checkbox.onCheckedChangedListener but it gives me Null Pointer at findViewByID. I checked, the ID I am looking for is alright, no typos in there.</p>
  
  <p>I'd like to make usage of this OnItemClickListener so later on I can play with the checkboxes. Any ideas?</p>
  
  <p>Code: </p>
  
  <p>ADAPTER: </p>
  
  <pre><code>public class FilterAdapter extends BaseAdapter {
  
      private Context mContext;
      private ArrayList&lt;String&gt; mFilters;
      private ArrayList&lt;Integer&gt; mPictures;
      private Typeface Bebas, DroidSans;
  
  
      public FilterAdapter(Context context, ArrayList&lt;String&gt; filters, ArrayList&lt;Integer&gt; pictures) {
          this.mContext = context;
          this.mFilters = filters;
          this.mPictures = pictures;
      }
  
      @Override
      public int getCount() {
          return mFilters.size();
      }
  
      @Override
      public Object getItem(int position) {
          return mFilters.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          if (convertView == null) {
              LayoutInflater mInflater = (LayoutInflater)
                      mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
              convertView = mInflater.inflate(R.layout.category_filter_item, null);
          }
  
          DroidSans = Typeface.createFromAsset(mContext.getAssets(), "fonts/DroidSans.ttf");
  
          ImageView filter_img = (ImageView) convertView.findViewById(R.id.category_picture);
          TextView filter_category = (TextView) convertView.findViewById(R.id.filter_category);
          CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.check_box);
  
  
  
          filter_category.setTypeface(DroidSans);
          filter_category.setText(mFilters.get(position));
          filter_img.setBackgroundResource(mPictures.get(position));
  
  
          return convertView;
      }
  }
  </code></pre>
  
  <p>Class where using the Adapter:</p>
  
  <pre><code>public class CheckinFilters extends Fragment {
  
      private ListView mListView;
      private FilterAdapter filterAdapter;
      private ArrayList&lt;String&gt; l = new ArrayList&lt;String&gt;();
      private ArrayList&lt;Integer&gt; drawables = new ArrayList&lt;Integer&gt;();
      private Typeface Bebas;
      private ArrayList&lt;Integer&gt; checkboxes = new ArrayList&lt;Integer&gt;();
      private SharedPreferences sharedPreferences;
      private SharedPreferences.Editor editor;
  
  
      public CheckinFilters() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          final View view = inflater.inflate(R.layout.fragment_checkin_filters, container, false);
  
  
          l.add("Chill");
          l.add("Eat");
          l.add("Explore");
          l.add("Move");
          l.add("Party");
          l.add("Whatever");
  
          drawables.add(R.drawable.category_chill);
          drawables.add(R.drawable.category_eat);
          drawables.add(R.drawable.category_explore);
          drawables.add(R.drawable.category_move);
          drawables.add(R.drawable.category_party);
          drawables.add(R.drawable.category_whatever);
  
          mListView = (ListView) view.findViewById(R.id.filter_list);
          filterAdapter = new FilterAdapter(view.getContext(), l, drawables);
          mListView.setAdapter(filterAdapter);
  
  
          sharedPreferences = getActivity().getPreferences(Context.MODE_PRIVATE);
          editor = sharedPreferences.edit();
  
          Bebas = Typeface.createFromAsset(view.getContext().getAssets(), "fonts/BebasNeue.otf");
  
          TextView mainHeader = (TextView) view.findViewById(R.id.filters_text);
          mainHeader.setTypeface(Bebas);
  
          SearchView filter_categories = (SearchView) view.findViewById(R.id.filter_categories);
  
          int searchImgID = getResources().getIdentifier("android:id/search_button", null, null);
          ImageView searchViewHint = (ImageView) filter_categories.findViewById(searchImgID);
          searchViewHint.setImageResource(R.drawable.ab_icon_search);
  
          int searchPlateID = filter_categories.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
          View searchPlateView = filter_categories.findViewById(searchPlateID);
          if (searchPlateView != null) {
              searchPlateView.setBackgroundResource(R.drawable.search_location_shape);
          }
  
          int searchViewID = filter_categories.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
          TextView textView = (TextView) filter_categories.findViewById(searchViewID);
          textView.setTextColor(Color.GRAY);
  
          CheckBox checkBox = (CheckBox) view.findViewById(R.id.check_box);
  
          return view;
      }
  
      private void save() {
          sharedPreferences = getActivity().getPreferences(Context.MODE_PRIVATE);
          editor = sharedPreferences.edit();
          editor.putInt("first", checkboxes.size());
  
          for (int i = 0; i &lt; checkboxes.size(); i++) {
              editor.remove("Status_" + i);
              editor.putInt("Status_" + i, checkboxes.get(i));
          }
  
          editor.commit();
      }
  
      private void load() {
          sharedPreferences = getActivity().getPreferences(Context.MODE_PRIVATE);
          int size = sharedPreferences.getInt("first", 0);
  
          for (int i = 0; i &lt; size; i++) {
              checkboxes.add(sharedPreferences.getInt("Status_" + i, 0));
          }
  
      }
  
      @Override
      public void onPause() {
          super.onPause();
          save();
      }
  
      @Override
      public void onResume() {
          super.onResume();
          load();
  
      }
  }
  </code></pre>
  
  <p>Layout I'm inflating for Adapter:</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="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#ECF0F1"&gt;
  
          &lt;ImageView
              android:id="@+id/category_picture"
              android:layout_width="70dp"
              android:layout_height="60dp"
              android:background="@drawable/sm_profile"/&gt;
  
          &lt;TextView
              android:id="@+id/filter_category"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerVertical="true"
              android:layout_toRightOf="@+id/category_picture"
              android:padding="10dp"
              android:text="Party"
              android:textColor="@color/enloop_dark_gray"
              android:textSize="18dp"/&gt;
  
          &lt;CheckBox
              android:id="@+id/check_box"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:layout_centerVertical="true"
              android:focusable="false"
              android:focusableInTouchMode="false"
              android:padding="10dp"/&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>