Peter,

SimpleCursorAdapter is the simplified version of the CursorAdapter.

You need to use "the real thing" and override newView() and bindView().

newView needs to load (inflate) a new list item layout.

bindView needs to set values in views contained in the list item layout to reflect values retrieved from its cursor.

The whole class might look something like this:

private static final class YourAdapter extends CursorAdapter {

YourAdapter(Context context, Cursor cursor) {
super(context, cursor);

mInflater = LayoutInflater.from(context);

mColField1 = cursor.getColumnIndex(<name of db field 1>);
mColField2 = cursor.getColumnIndex(<name of db field 2>);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mInflater.inflate(R.layout.my_list_item, parent, false);
return v;
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
// show text value
TextView tv = (TextView) view.findViewById(R.id.item_field_1);
tv.setText(cursor.getString(mColField1));

// show icon
ImageView iv = (ImageView) view.findViewById(R.id.item_field_2);
int icon_kind = cursor.getInt(mColField2);

iv.setImageResource(<some resource id value based on icon_kind>);
}


LayoutInflater mInflater;

private int mColField1;
private int mColField2;

}

-- Kostya

31.10.2010 12:12, Peter Webb пишет:
I'm an Android newbie, stuck on a problem for a over week now, if I
knew what I was doing it would be 10 minutes work.

Im using the NotePad example as a base for an application. This binds
a ListActivity to a Provider.

Its perfect, except it uses SimpleCursorAdaptor, which means the list
only binds to and displays one item per row. I want it to display two
items, both bound the Provider. Or more accurately display the text
from one Content Provider field and an icon which depends on the value
of a different field.

This sounds like a pretty simple thing to do, a very slight
modification to the NotePad application. Trouble is, I have no idea on
*how* to do it. I really need a starting point, and "approach" to use.

So far I have tried (unsuccessfully):

* Hand populating the ListView by reading in the Provider data and
populating an array in OnCreate. This works, except as the data is not
bound the List does not update when I add an item.

* Extending SimpleCursorAdapter with a custom getViewBinder. Could
still only bind to a single column.

* Building my own ListAdaptor. Couldn't get this to work.

* Concatenating both fileds together and "parsing" 2 fields into 1
field read/write.

The next thing I will try is extremely tacky running two separate
simpleCursorAdaptors in two views in a Linear Layout, fudged so the
row height is identical, and duplicate the logic.

I say this only to show that I really, really have tried.

Could someone give me at least a hint as to how I can create a custom
CursorAdaptor which binds to two fields instead of just one like
SimpleCursorAdapter? There must be some easy way ????

Sorry/thanks/help

Peter Webb



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to