title: changing background color of rows in listview through an adapter
body: <p>I'm trying to implement a gmail like selection behavior: When I click on a item, it's either selected or deselected and a custom color is drawn over the selected items. I'm using <a href="https://stackoverflow.com/questions/10447238/how-to-change-background-color-of-selected-items-in-listview">this</a> as a reference.</p>
  
  <p>For some reason it only works after I select/deselect a few items. After that, getView() is called and everything works as expected.
  Why isn't getView() called from the beginning?</p>
  
  <p>ListActivity:</p>
  
  <pre><code>@Override
  public void onListItemClick(ListView parent, View view, int position, long id) {
      super.onListItemClick(parent, view, position, id);
      mSimpleCursorAdapter.toggleSelected(new Integer(position));
  }
  </code></pre>
  
  <p>Adapter:</p>
  
  <pre><code> public ArrayList&lt;Integer&gt; selectedIds = new ArrayList&lt;Integer&gt;();
  
  @Override
   public View getView(int position, View convertView, ViewGroup parent) {
      mCursor = (Cursor) getItem(position);
      ViewHolder holder = null;
      int col = -1;
  
      if(convertView == null) 
      {   
          holder = new ViewHolder();
          convertView = mInflater.inflate(R.layout.row, parent, false);
  
          holder.mTitle = (TextView) convertView.findViewById(R.id.titleID);
          convertView.setTag(holder);
  
      } else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      col = mCursor.getColumnIndex(ReminderColumns.TITLE);
      holder.mTitle.setText(mCursor.getString(col));
  
      if (selectedIds.contains(position)) {
          convertView.setSelected(true);
          convertView.setPressed(true);
          convertView.setBackgroundColor(mContext.getResources().getColor(R.color.orange));
      }
      else
      {
          convertView.setSelected(false);
          convertView.setPressed(false);
          convertView.setBackgroundColor(mContext.getResources().getColor(R.color.white));
      }   
  return convertView; 
  }
  
  public void toggleSelected(Integer position)
  {
      if(selectedIds.contains(position))
      {
          selectedIds.remove(position);
      }
      else
      {
          selectedIds.add(position);
      }
  }
  </code></pre>