title: CursorAdapter changed style of SwipeMenuListView after scroll
body: <p>I'm trying to develop an app to record debts in which I have a SwipeMenuListView from this github <a href="https://github.com/baoyongzhang/SwipeMenuListView" rel="nofollow">https://github.com/baoyongzhang/SwipeMenuListView</a> for adding a swipe menu. Using a custom CursorAdapter, I populate the ListView with the name and total debt.</p>
  
  <p>Now, I want to group each listview items depending on the due date. I've created a new column on my SQLite to add a header for each day. Now I just need to use different style for header and items of the ListView. By detecting the new column from bindView and depending on if it's a header or items, it will change, hide and show elements from the same layout.</p>
  
  <p>The problem is that when I scroll the ListView, some of the listview items changed style. It get worse if I keep scrolling up and down. <a href="http://i.stack.imgur.com/DYaBz.jpg" rel="nofollow">Here's the picture of the error from the listview.</a> Notice that it's all in one session, the header style seems to have been used in some of the items and the header itself changed to red color which suppose to be color code for the items. If I click one of the item, it still get the correct item so I figure its a problem within the cursorAdapter but I just can't figure it out. It is not a mistake in the SQL database which I have checked. </p>
  
  <p>Here's the cursorAdapter.</p>
  
  <pre><code>public class DebtCursorAdapterMain extends CursorAdapter {
  public DebtCursorAdapterMain(Context context, Cursor c, int flags) {
      super(context, c, flags);
  }
  
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
      return LayoutInflater.from(context).inflate(R.layout.debt_list_item, parent, false);
  }
  
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
      int x = Integer.parseInt(cursor.getString(cursor.getColumnIndex(DBHelper.DATE_SEPARATOR_COLUMN)));
  
      TextView tvName = (TextView) view.findViewById(R.id.tvName);
      TextView tvTotal = (TextView) view.findViewById(R.id.tvTotal);
  
      if(x == 0) {
          DecimalFormat df = new DecimalFormat("#.00");
  
          String nameText = cursor.getString(cursor.getColumnIndex(DBHelper.NAME_COLUMN));
          String totalText = "$ " + df.format(cursor.getDouble(cursor.getColumnIndex(DBHelper.TOTAL_COLUMN)));
          String type = cursor.getString(cursor.getColumnIndex(DBHelper.TYPE_COLUMN));
  
          if (tvName != null)
              tvName.setText(nameText);
          if (tvTotal != null)
              tvTotal.setText(totalText);
  
          if (type.equals("L"))
              view.setBackgroundColor(Color.parseColor("#ff9999"));
          if (type.equals("B"))
              view.setBackgroundColor(Color.parseColor("#99ff99"));
      }
      if(x == 1){
          String date = cursor.getString(cursor.getColumnIndex(DBHelper.DUE_DATE_COLUMN));
          if (tvName != null &amp;&amp; tvTotal != null) {
              tvName.setText(date);
              tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
              tvTotal.setVisibility(View.GONE);
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the main activity in which the cursorAdapter is called.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      // Find SwipeMenuListView
      final SwipeMenuListView swipeMenuList = (SwipeMenuListView) findViewById(R.id.swipeMenuList);
      // Create Debt database cursor adapter
      cursorAdapter = new DebtCursorAdapterMain(this, null, 0);
      // Create SwipeMenuList and set item
      SwipeMenuCreator creator = createMainActivitySwipeMenu();
      swipeMenuList.setMenuCreator(creator);
      swipeMenuList.setAdapter(cursorAdapter);
      swipeMenuList.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);
  
      // Set SwipeMenuList on item's menu click
      swipeMenuList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
              ....
          }
      });
  
      // Swipe menu on Click function
      swipeMenuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long id) {
              ....
          }
      });
  
      // Initialize cursor and check database for updating top info
      getLoaderManager().initLoader(0, null, this);
      checkDataBase();
  }
  </code></pre>
  
  <p>I'm still new in android development so please tell me if there's a better approach to this problem. Thanks guys.</p>