title: ListView loosing track of positions
body: <p>I'm working on a quite heavy ListView app where the listitems are quite heavy. When the user only has a few listitems everything works fine but when the user adds more some problems begin to surface. Interaction with the listitems become harder and sometimes when a item is clicked the user gets the touch effect but no effect. When accesing positions (this is done when using the Contextual Action Bar <a href="http://developer.android.com/guide/topics/ui/menus.html#CAB" rel="nofollow">http://developer.android.com/guide/topics/ui/menus.html#CAB</a> ) the click throws a NullPointerException. I'm pretty sure this is because of the GC killing resources in my app. Are there any general tips on how to avoid this kind of behaviour or possibly some kind of workaround to fix this?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Logcat crash:</p>
  
  <pre><code>01-07 15:59:39.219: E/AndroidRuntime(8003): FATAL EXCEPTION: main
  01-07 15:59:39.219: E/AndroidRuntime(8003): java.lang.NullPointerException
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at     com.simon.holocountownapp.MainActivity$1.onItemCheckedStateChanged(MainActivity.java:104)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView$MultiChoiceModeWrapper.onItemCheckedStateChanged(AbsListView.java:6037)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView.setItemChecked(AbsListView.java:1013)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView.performLongPress(AbsListView.java:2807)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:2765)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at  android.os.Handler.handleCallback(Handler.java:725)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.os.Handler.dispatchMessage(Handler.java:92)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.os.Looper.loop(Looper.java:137)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.app.ActivityThread.main(ActivityThread.java:5191)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at java.lang.reflect.Method.invokeNative(Native Method)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at java.lang.reflect.Method.invoke(Method.java:511)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
  01-07 15:59:39.219: E/AndroidRuntime(8003):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Line 104 (referenced in logcat) calls listView.getChildAt(position) and this most likely returns null which leads to the crash.</p>
  
  <p>The layout is pretty heavy (200+ lines of code) so I'll post it to pastebin.
  <a href="http://pastebin.se/KTmCA0jc" rel="nofollow">http://pastebin.se/KTmCA0jc</a></p>
  
  <p>The adapter:</p>
  
  <pre><code>   @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          CountdownViewHolder holder;
          CountdownItem ci = mTitle.get(position);
  
      if (convertView == null) {
          convertView = mInflater.inflate(R.layout.list_item_layout, parent,
                  false);
  
          holder = new CountdownViewHolder();
          holder.mTitle = (TextView) convertView.findViewById(R.id.textPrim);
          holder.mSubtitle = (TextView) convertView
                  .findViewById(R.id.textSec);
          holder.mOverflow = (ImageButton) convertView
                  .findViewById(R.id.overflow);
          holder.mInfo = (ImageButton) convertView.findViewById(R.id.info);
          holder.expand_layout = (LinearLayout) convertView
                  .findViewById(R.id.expand_layout);
          holder.mExpDay = (TextView) convertView.findViewById(R.id.exp_day);
          holder.mExpSec = (TextView) convertView.findViewById(R.id.exp_sec);
          holder.mDayProgress = (ProgressBar) convertView
                  .findViewById(R.id.day_progress);
          holder.mMonthProgress = (ProgressBar) convertView
                  .findViewById(R.id.month_progress);
          holder.mYearText = (TextView) convertView
                  .findViewById(R.id.year_text);
          holder.day_help = (TextView) convertView
                  .findViewById(R.id.day_help);
          holder.month_help = (TextView) convertView
                  .findViewById(R.id.month_help);
  
          holder.setTag(position);
          holder.setupInfoClickActions();
          holder.setupOnClickListener();
          holder.setTitle(ci.getTitle());
          holder.setSubtitle(ci.getSubtitle());
          holder.fixImageAndText(position);
  
          convertView.setTag(holder);
      } else {
          holder = (CountdownViewHolder) convertView.getTag();
      }
  
      holder.manageExpand(ci.getExpand(), ctx, position, mTitle.size());
  
      return convertView;
  }
  </code></pre>