title: The first item in my ListView will not update when I change the text of an already visible TextView
body: <p>I have a ListView that is getting populated by my custom BaseAdapter with views that contain a couple of TextViews and ImageButtons. If the user selects an item from a PopupMenu on one of the list items, it changes the text of an associated TextView on that list item. This is working great for all of the items in my ListView except the first one. The first item never updates the TextView for some reason. I suspect it has something to do with my convertView for that item not getting reset, but I'm not sure how to go about fixing it. </p>
  
  <p>Here is my setup. I have a ListView that is getting populated by a custom BaseAdapter. In my BaseAdapter, I have this for my <code>getView()</code>:</p>
  
  <pre><code>public View getView(int position, View convertView, ViewGroup parent) {
      if(convertView == null) {
          IMOModGroup modGroup = modGroups.get(position);
          convertView = modGroup.getConvertView(parent);
      } 
      return convertView;
  }
  </code></pre>
  
  <p>IMOModGroup is a special data structure that holds all the states and data for each list item. So when the convertView comes in null, the BaseAdapter requests a new convertView from the IMOModGroup for that position. Here's the IMOModGroup method that creates the new convertView:</p>
  
  <pre><code>public View getConvertView(ViewGroup parent) {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(R.layout.modifier_list_item, parent, false);
  
      //...
  
      TextView selectedModText = (TextView) convertView.findViewById(R.id.modName);
      selectedModText.setText(R.string.no_modifier_selected);
      selectedModText.setTextColor(context.getResources().getColor(R.color.grayed_out_text_color));
  
      //...
  
      return convertView;
  }
  </code></pre>
  
  <p>The user can open a PopupMenu on each list item and make a selection. When they do this, the TextView in the above code is changed to reflect the selection with new text. That code looks like this:</p>
  
  <pre><code>public boolean onMenuItemClick(MenuItem item) {
      String selectedMod = item.getTitle().toString();
  
      TextView selectedModText = (TextView) convertView.findViewById(R.id.modName);
      selectedModText.setText(selectedMod);
      selectedModText.setTextColor(context.getResources().getColor(R.color.imo_blue_light));
  
      //...
  
      return false;
  }
  </code></pre>
  
  <p>All of this is working great on every item in the ListView except for the very first one, which never updates to reflect the TextView change. I've tested to make sure the TextView text is actually getting changed and can be called and viewed at a later time, and it's being set correctly. So it seems like the data is correct, but the view is not getting updated. </p>
  
  <p>I'm pretty sure the problem is that my convertView is not getting reset, so the ListView is just continuing to use the old view with the old text. I tried calling <code>notifyDataSetChanged()</code> on the BaseAdapter after I set the text, and that didn't work. </p>
  
  <p>This question looks promising: <a href="https://stackoverflow.com/questions/6804157/first-item-in-list-view-is-not-displaying-correctly">First item in list view is not displaying correctly</a></p>
  
  <p>But I'm not sure if that's my problem or not, and I'm not sure how I would apply that to my scenario.</p>
  
  <p>Any ideas? I've read through a few similar questions on SO and Google, but none of them really seemed to be relevant to my specific scenario. I've been using ListViews and Adapters for quite a while now and this is the first time I've seen something like this. Thanks for your help.</p>
  
  <hr>
  
  <p><strong>EDITS IN RESPONSE TO COMMENTS</strong></p>
  
  <p>Here is the complete BaseAdapter code...</p>
  
  <pre><code>import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  
  import java.util.ArrayList;
  
  public class IMOModListAdapter extends BaseAdapter {
  
      private Context context;
      private ArrayList&lt;IMOModGroup&gt; modGroups;
  
      public IMOModListAdapter(Context context, ArrayList&lt;IMOModGroup&gt; modGroups) {
          this.context = context;
          this.modGroups = modGroups;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          if(convertView == null) {
              IMOModGroup modGroup = modGroups.get(position);
              convertView = modGroup.getConvertView(parent);
          }
          return convertView;
      }
  
      public Object getItem(int position) {
          return 0;
      }
  
      public long getItemId(int position) {
          return 0;
      }
  
      public int getCount() {
          return modGroups.size();
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>FURTHER TESTING</strong></p>
  
  <p>As I digged deeper into my debugging, I realized that when the TextView for element 1 in the list is changed, <code>getView()</code> is not even called at all. But when any of the other elements are changed, <code>getView()</code> is called as normal. </p>
  
  <p>As a sanity check, I tried changing the text of the first list item from the outside, from the parent Activity itself. If I try to change the first item, it does nothing, but if I try to change any of the other list items, it works fine! This is so bizarre! This is what I tried:</p>
  
  <pre><code>//Set the text of the first item. This does NOTHING and the TextView
  //in the item remains unchanged
  IMOModGroup modGroup = modGroups.get(0);
  modGroup.setTestText("This is some test text");
  modList.notifyDataSetChanged();
  
  //Set the text of the second item. This works completely fine!!!!!
  IMOModGroup modGroup = modGroups.get(1);
  modGroup.setTestText("This is some test text");
  modList.notifyDataSetChanged();
  </code></pre>