views:

1192

answers:

2

Firstly, I have found many examples of how to grab data from a db and place it into a list, however this seems to be all for ListActivites.

My list is part of the UI and therefore I can't use a ListActivity because it does not consume the whole screen (or can I?).

This is the UI:

<SlidingDrawer android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
   android:id="@+id/Drawer"
  android:orientation="vertical"
  android:handle="@+id/handle" 
   android:content="@+id/content">

<ImageView
android:id="@id/handle"
android:src="@drawable/tray_handle_normal"
android:layout_height="wrap_content" android:layout_width="wrap_content"/>

<RelativeLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@id/content" android:background="@color/black">


<ListView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/List">
</ListView>

</RelativeLayout>

So, from what ive read I need to grab the data from the db, then place it into some sort of array then use an array adapter to fill the list view. Is that correct? If so, is there some sample code because all I can find is code releated to ListActivites.

+1  A: 

I think you can use a SimpleCursorAdapter for this.

I think the Notepad tutorial uses it. If you need more complicated things, it's just a matter of you implementing your own view adapter. Here's sample code that shows you how to do it.

JRL
+2  A: 

You can still use a ListActivity. The magic is to set the id of your ListView to "@android:id/list". However, ListActivity is just a convenience. You can get the same result by creating an adapter (look at ArrayAdapter or SimpleCursorAdapter) and connecting it to the ListView by hand.

Erich Douglass
ah, I was wondering how I could use a list Activity. Thanks, this answers it kinda.Just after posting the solution I found how to do it...its always the way.....!
Tom