3

Ok, I have been searching thick and thin, and I am having some issues implementing a BaseAdapter.

I have been able to implement a Simple Cursor Adapter http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List7.html as per the example above.

There is a pretty good BaseAdapter example here : List14 google example

I am wanting to create my own List Adapter using BaseAdapter to show a listView, with multiple items from a Database. I know this can be done using the Simple Cursor Adapter, but I am looking to handle rows differently, so I want to be able to draw each row by overriding getView. The data would be pulled from a cursor.

I know this code is ugly for getting to the cursor data, but assuming I have populated a cursor. What suggestions do you have on this if column 8 contains the image resource id. :

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    cursor.moveToPosition(position);
    ImageView i = new ImageView(mContext);
    i.setImageResource(cursor.getShort(8));
    i.setAdjustViewBounds(true);
    i.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    return i;
}

Do you have any good examples of a BaseAdapter being drawn using a cursor?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Chrispix
  • 17,941
  • 20
  • 62
  • 70
  • Could you provide a little more detail on what you're trying to achieve / what's not working as you expect. What does the code you've shown do when you run it? How is that different from what you're trying to do? – Reto Meier Feb 12 '09 at 11:26
  • Actually after a few more hours of digging around, I think I got it to work in some fashion. My biggest issue is if I delete an item from a row my listview is not updating, even w/ a mAdapter.notifiyDataSetChanged(); – Chrispix Feb 12 '09 at 13:21

1 Answers1

5

Try calling notifyDataSetChanged() from a method inside the BaseAdapter itself.

See the methods in List8 of the API Demos as an example.

Matt
  • 774
  • 8
  • 16