Is ListActivity rowid = _id?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Is ListActivity rowid = _id?

Postby sbirnie » Fri Dec 04, 2009 11:52 pm

Don't know if this should go under the database or view section. I'm creating a ListActivity that is being populated from a sqlite3 db. I extended BaseAdapter to populate the view because I saw that done in a sample somewhere (This is my first attempt at an Android app).

In all the examples they're using an ListArray instead of a database so the getItemId just returns the position of the list.

I don't think I can extend CursorAdapter because I need to take one of the columns which contains a url and create a Bitmap to assign it to an imageview.

Long story semi-short, while I'm assigning all the data to the row, where does the _id get assigned? I need it for updates/deletes/details. Is that assigned to the rowid automatically or do I need to put it in a hidden field somewhere or something like that? I assume it can't be the rowid because what if I have a order by clause that isn't by _id?

Thanks for any help in advance.
sbirnie
Freshman
Freshman
 
Posts: 2
Joined: Fri Dec 04, 2009 10:26 pm

Top

Postby sbirnie » Sun Dec 06, 2009 1:14 am

Couple of views - no answers?
sbirnie
Freshman
Freshman
 
Posts: 2
Joined: Fri Dec 04, 2009 10:26 pm

Postby achie1266 » Sun Dec 06, 2009 7:24 pm

sbirnie wrote:Couple of views - no answers?


Notepad tutorial does exactly what you need.
http://developer.android.com/guide/tuto ... index.html
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Droid123 » Mon Dec 07, 2009 10:33 am

The data from the database is bound to the ListAdapter by means of a Cursor Object. Every item in the ListAdapter is a different row from the database

If you want to get the _id value of a certain row, select an item in the List and just do:
Cursor cursor;
int value = cursor.getInt(cursor.getColumnIndex("_id"));

EDIT:
I just re-read your post and to be a bit more clear:
I found that when dealing with listview and databases, use a "ListActivity" which supports 1 ListView and 1 ListAdapter. Use a SimpleCursorAdapter to bind the data from the database to the ListAdapter. Every item in the ListAdapter now holds a Cursor object, which basically is a pointer to a specific row in the database.

In my implementation I've saved a URI to an Image in my database and I can retrieve the URI with:
Uri.Parse(cursor.getString(cursor.getColumnIndex("Image")));
After that I can use that URI as data in my Intent to view the image.
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests