title: SimpleCursorAdapter bindView and recycled views
body: <p>I've seen previous topics on the subject like this one: <a href="https://stackoverflow.com/questions/5183813/android-issue-with-newview-and-bindview-in-custom-simplecursoradapter">Android: Issue with newView and bindView in custom SimpleCursorAdapter</a> and still can't understand what the problem with my code is. I've read books on it, etc, etc and can't get it why I'm not getting it right.</p>
  
  <p>The problem is when I scroll my listView I get rows with the wrong data but if I click the row and get into the next activity it correspond to the data it's supposed to have.</p>
  
  <p>I implemented a viewHolder for the date to bind to the rows in the newView / bindview methods.</p>
  
  <p>Everything displays well till I start to scroll the list view. That's when the rows start to get all mixed up. That has to do with the recycling of views, that I know, how to fix it, that I'm still trying to figure it out. I would love any help!</p>
  
  <p>The code of my SimplecursorAdapter:</p>
  
  <pre><code>public class DropNotesAdapter extends SimpleCursorAdapter {
  
  private LayoutInflater layoutInflater;
  private Utils mUtils = new Utils();
  private int layout;
  private int titleColIndex;
  private int modifiedColIndex;
  private int priorityColIndex;
  
  public DropNotesAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
  
      super(context, layout, c, from, to);
      this.layout = layout;
      layoutInflater = LayoutInflater.from(context);
      titleColIndex = c.getColumnIndex(DropNotesDBAdapter.KEY_TITLE);
      modifiedColIndex = c.getColumnIndex(DropNotesDBAdapter.KEY_MODIFIED);
      priorityColIndex =c.getColumnIndex(DropNotesDBAdapter.KEY_PRIORITY);
  }
  
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
  
      View view = layoutInflater.inflate(layout, parent, false);
  
      TextView titleText = (TextView) view.findViewById(R.id.title_line);
      TextView modifiedText = (TextView) view.findViewById(R.id.date_line);
      ImageView priorityTag = (ImageView) view.findViewById(R.id.item_priority);
  
      NoteHolder holder = new NoteHolder();
      holder.titleView = titleText;
      holder.modifiedView = modifiedText;
      holder.priorityView = priorityTag;
      holder.title = cursor.getString(titleColIndex);
      holder.modified = mUtils.formatDate(mUtils.formatDateFromString (cursor.getString(modifiedColIndex), context, "dd-MM-yyyy"));
      holder.priorityResId = mUtils.getPriorityResourceId(cursor.getInt(priorityColIndex));
      view.setTag(holder);
  
      return view;
  }
  
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
  
      NoteHolder holder = (NoteHolder) view.getTag();
  
      holder.titleView.setText(holder.title);
      holder.modifiedView.setText(holder.modified);
      holder.priorityView.setImageResource(holder.priorityResId);
  
      Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/ARLRDBD.TTF");
      holder.titleView.setTypeface(tf);
      holder.modifiedView.setTypeface(tf);
  }
  
  private static class NoteHolder {
      TextView titleView;
      TextView modifiedView;
      ImageView priorityView;
      String title;
      String modified;
      int priorityResId;
  }
  </code></pre>
  
  <p>}</p>