After digging a bit further into this group and reading the
documentation some more I think I have even simpler mechanism than
that above.

1) Include the column(s) you want to convert into icons in the adapter
assignment. In this case the last column 'type' is a string which like
"0", "1"...etc.

        TrafficDataAdapter trafficAdapter = new
TrafficDataAdapter(this,
                                                                 
R.layout.situation_row,
                                                                 mCursor,
                                                                 PROJECTION,
                                                                 new int[] { 
R.id.title,
R.id.description, R.id.type});

2) My sub-classed adapter is now:

public class TrafficDataAdapter extends SimpleCursorAdapter
{

    public TrafficDataAdapter(Context context, int layout, Cursor
c,String[] from, int[] to)
    {
        super(context, layout, c, from, to);

        setViewBinder(new TrafficDataViewBinder());
    }

}


Note the call to "setViewBinder".

3) The TrafficDataViewBinder class implements a setViewValue call
which according to the documentation:

"This class can be used by external clients of SimpleCursorAdapter to
bind values fom the Cursor to views. You should use this class to bind
values from the Cursor to views that are not directly supported by
SimpleCursorAdapter or to change the way binding occurs for views
supported by SimpleCursorAdapter".

If I have understood this correctly the textviews will get handled
automatically. The imageview will trigger a call to the "setViewValue"
method in the binder where we can test for the column in question and
set an image based on the field value. i.e.

public class TrafficDataViewBinder implements
SimpleCursorAdapter.ViewBinder
{
        @Override
        public boolean setViewValue(View view, Cursor cursor, int
columnIndex)
        {

          int nImageIndex = cursor.getColumnIndex(TrafficData.Strings.TYPE);
          if(nImageIndex==columnIndex)
          {
              ImageView typeControl = (ImageView)view;
              int type =
Integer.parseInt(cursor.getString(nImageIndex));
 
typeControl.setImageResource(TrafficData.getTypeResource(type));
              return true;
          }

          return false;
        }

}

Al.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to