Search code examples
androidlistviewcursorsimplecursoradapter

Android: ViewBinder - modifying ListView columns larger than Cursor content


I have a ListView which shows 3 values from an SQLite database (columns 1, 2 & 3). To the right of those values I want to put some ImageButtons. My question is - how do I modify what appears in columns 4 and above?

I have overridden setViewValue() but this only gets called for columns in the Cursor (sort of what I would expect). How can I modify what appears in a particular row for columns 4 and above? Would I override the getView() method somehow? If I'm using a SimpleCursorAdapter - does that mean that I should be creating a subclass of SimpleCursorAdapter and then overriding the getView() method?


Solution

  • This is how I did it:

      public class CustomViewBinder implements ViewBinder
      {
        @Override
        public boolean setViewValue( View view, Cursor cursor, int columnIndex )
        {
          if( columnIndex == 1 )
          {
            View vParent = (View) view.getParent();
    
            ImageView ivPlaylist = (ImageView) vParent.findViewById( R.id.ibAddPlaylist );
    
            if( ivPlaylist != null )
            {  
              ivPlaylist.setImageResource( R.drawable.clipboard30x30purple );
            }