Вот мой пример для строки, построенной из двух записей из db + image (в настоящее время - одно изображение для любой строки, но его можно улучшить для конкретного изображения из db):
public class DomainAdapter extends SimpleCursorAdapter{
private Cursor dataCursor;
private LayoutInflater mInflater;
....
public DomainAdapter(Context context, int layout, Cursor dataCursor, String[] from,
int[] to) {
super(context, layout, dataCursor, from, to);
this.dataCursor = dataCursor;
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(layout, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.test_track);
holder.text2 = (TextView) convertView.findViewById(R.id.test_band);
holder.icon = (ImageView) convertView.findViewById(R.id.test_artwork);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
// Cursor to current item
dataCursor.moveToPosition(position);
int title_index = dataCursor.getColumnIndex(fields[0]);
String title = dataCursor.getString(title_index);
int description_index = dataCursor.getColumnIndex(fields[1]);
String description = dataCursor.getString(description_index);
holder.text1.setText(title);
holder.text2.setText(description);
holder.icon.setImageResource(R.drawable.alert_dialog_icon);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
ImageView icon;
}
}
и с использованием этого адаптера:
databaseListAdapter = new DomainAdapter(this,
R.layout.test_layout,
databaseCursor,
new String[] {"title", "description"},
new int[] { R.id.test_track, R.id.test_track });
databaseListAdapter.notifyDataSetChanged();
DomainView.setAdapter(databaseListAdapter);
и макет:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64dip"
android:padding="6dip">
<TextView
android:id="@+id/test_band"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="@+id/test_track"
android:layout_alignLeft="@id/test_track"
android:layout_alignParentBottom="true"
android:gravity="top" />
<TextView
android:id="@id/test_track"
android:layout_marginLeft="6dip"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@+id/test_artwork"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="bottom" />
<ImageView
android:id="@id/test_artwork"
android:layout_width="56dip"
android:layout_height="56dip"
android:layout_gravity="center_vertical" />
</RelativeLayout>