[mono-android] SimpleCursorAdapter and SimpleCursorAdapter.CursorToStringConverter

Tom Opgenorth tom at opgenorth.net
Sun Jan 15 04:47:29 UTC 2012


Porting some Java to C# again. In Java I was doing it this way:
adapter.setCursorToStringConverter(new
SimpleCursorAdapter.CursorToStringConverter() {
            @Override
            public CharSequence convertToString(Cursor cursor) {
                final int colIndex =
cursor.getColumnIndexOrThrow(VehicleDescriptionsTable.DESCRIPTION);
                return cursor.getString(colIndex);
            }
        });


Now, in M4A, it seems to me that I probably need to implement
SimpleCursorAdapter.ICursorToStringConverter like so:

public class VehicleTripDescriptionCursorToStringConverter :
Java.Lang.Object,    SimpleCursorAdapter.ICursorToStringConverter
    {
        public ICharSequence ConvertToStringFormatted(ICursor cursor)
        {
            var colIndex =
cursor.GetColumnIndexOrThrow(VehicleTripDescriptionTable.Columns.DESCRIPTION);
            var value = cursor.GetString(colIndex);
            return new Java.Lang.String(value);
        }
    }


and then in my adapter I can go:
adapter.CursorToStringConverter = new
VehicleTripDescriptionCursorToStringConverter();

Is this the correct way to port this code over?  Or is there a simpler way.
-- 
http://www.opgenorth.net


More information about the Monodroid mailing list