title: How to show/hide check boxes in ListView programmatically
body: <p>I have next problem: I use following adapter to populate ListView:</p>
  
  <pre><code>public class PlaylistCursorAdapter extends CursorAdapter{
  
  public PlaylistCursorAdapter(Context context, Cursor cursor){
      super(context, cursor, 0);
  }
  
  public static class ViewHolder{
      CheckBox checkBox;
      TextView playlistTitle;
  
      public ViewHolder(View view){
  
          checkBox = (CheckBox)view.findViewById(R.id.checkBox);
          playlistTitle = (TextView)view.findViewById(R.id.playlistTitle);
      }
  }
  
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
      View view = LayoutInflater.from(context).inflate(R.layout.playlist_item, viewGroup, false);
      ViewHolder viewHolder = new ViewHolder(view);
      view.setTag(viewHolder);
      return view;
  }
  
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
  
      ViewHolder viewHolder = (ViewHolder)view.getTag();
      viewHolder.checkBox.setVisibility(View.GONE);
  
      int playlistName = cursor.getColumnIndex(MediaStore.Audio.Playlists.NAME);
      String playlist = cursor.getString(playlistName);
  
      viewHolder.playlistTitle.setText(playlist);
  }
  }
  </code></pre>
  
  <p>As you can see, I have checkbox in the row which is gone in the very beggining and what I want to do is to show all of them(checkboxes) when onItemLong is performed.</p>
  
  <p>Actually I already implemented onItemLong in my activity and I was nearly done with that task with following code:</p>
  
  <pre><code> public void showCheckBoxes(){
      for(int i = 0; i != playlist.getAdapter().getCount(); i++) {
  
          mCheckBox = (CheckBox) playlist.getChildAt(i).findViewById(R.id.checkBox);
          mCheckBox.setVisibility(View.VISIBLE);
          getActivity().invalidateOptionsMenu();
      }
  }
  </code></pre>
  
  <p>The method works fine until you can see all items in ListView on a screen.
  But then I noticed that (mCheckBox = (CheckBox) playlist.getChildAt(i).findViewById(R.id.checkBox);) - is actually new problem, because if my listview is longer than screen, I always get the following error - (java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference) and then app crashes.</p>
  
  <p>Yep, I understand why is it happens, but have no idea how to solve the problem.</p>
  
  <p>Will really appreciate if someone will give me answer, hint, link or some idea how to solve the problem.</p>
  
  <p>Is it somehow possible to change code to show/hide checkboxes. Maybe there is a way to do that without calling .findViewById all the time.</p>
  
  <p>Thank you in advance.</p>