title: Custom Adapter getView method called frequently with position 0
body: <p>I have a GridView bound to a custom ArrayAdapter derivation. </p>
  
  <pre><code>&lt;GridView
          android:id="@+id/measurements"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:columnWidth="100dp"
          android:gravity="center"
  
  
          android:numColumns="auto_fit"
          android:orientation="horizontal"
          android:stretchMode="columnWidth"/&gt;
  </code></pre>
  
  <p>Each item is inflated to a view (I use the view-recycling pattern) as shown below.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" 
      android:orientation="vertical" android:background="#8800CC00"&gt;
  
      &lt;TextView android:id="@+id/widget_view_id" 
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
      &lt;TextView android:id="@+id/widget_status" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent"
          android:layout_gravity="center"/&gt;
      &lt;TextView android:id="@+id/widget_timestamp" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_gravity="center"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I have a HandlerThread that then populates each widget with data values on a periodic basis.</p>
  
  <p>However I see that the first view is 'frozen' - no updates. LogCat shows me that
  adapter#getView(position = 0) is being called almost as if it's in a loop.</p>
  
  <pre><code>public class WidgetAdapter extends ArrayAdapter&lt;DataItem&gt;
      {
          private DataServiceProxy _dataServiceProxy;
  
          public WidgetAdapter(Context context, List&lt;DataItem&gt; objects, DataServiceProxy dataServiceProxy) {
              super(context, 0, objects);
              _dataServiceProxy = dataServiceProxy;
  
          }
  
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
  
                  View view;
                  DataItem dataItem = getItem(position);
  
                  if (convertView == null)
                  {
                      view = getActivity().getLayoutInflater().inflate(R.layout.item_dataItem, parent, false);
                      view.setPadding(8, 8, 8, 8);
                  }
                  else
                  {
                      view = convertView;
                      int oldId = ((Integer)view.getTag()).intValue();
                      _dataServiceProxy.removeListener(WidgetView.getFor(view), oldId);
                  }
  
                  ((TextView) view.findViewById(R.id.widget_view_id)).setText("View# " + dataItem.id);
                  view.setTag(Integer.valueOf(dataItem.id));
  
                  _dataServiceProxy.addListener(new WidgetView(view, dataItem), dataItem.id);
                  return view;
          }
  ...     
  </code></pre>
  
  <p>The last time this happened, I had fixed it - by replacing height='wrap_content' to 'match_parent' in all GridView item template sub-views. (Ref:Romain Guy's Google IO talk )</p>
  
  <p>But it's back and driving me nuts...</p>
  
  <p>Call stack when I set a breakpoint at the getView(pos=0) shows </p>
  
  <blockquote>
    <p>Thread [&lt;1> main] (Suspended (breakpoint at line 255 in
    WidgetFragment$WidgetAdapter))              WidgetFragment$WidgetAdapter.getView(int, View,
    ViewGroup) line: 255      GridView(AbsListView).obtainView(int,
    boolean[]) line: 2456     GridView.onMeasure(int, int) line: 1030 
      GridView(View).measure(int, int) line: 15562<br>
      RelativeLayout.measureChildHorizontal(View,
    RelativeLayout$LayoutParams, int, int) line: 617<br>
      RelativeLayout.onMeasure(int, int) line: 399<br>
      RelativeLayout(View).measure(int, int) line: 15562<br>
      FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int,
    int) line: 5109       FrameLayout.onMeasure(int, int) line: 310<br>
      FrameLayout(View).measure(int, int) line: 15562 
      FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int,
    int) line: 5109       FrameLayout.onMeasure(int, int) line: 310<br>
      FrameLayout(View).measure(int, int) line: 15562 
      LinearLayout.measureVertical(int, int) line: 833<br>
      LinearLayout.onMeasure(int, int) line: 574<br>
      LinearLayout(View).measure(int, int) line: 15562<br>
      PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int,
    int, int, int) line: 5109</p>
  </blockquote>