Computation on db data then list them using either SimpleCursorAdapter or ArrayAdapter

by kc2uno_CMU » Fri, 23 Apr 2010 13:53:48 GMT

Sponsored Links
 Hi all,

I juststarted programming in android a few weeks ago, so I am not
entirely sure how to deal with listing values. Please help me out!
I have some questions regarding displaying data sets from db in a
list. Currently I have a cursor returned by my db points to a list of
rows and I want display 2 columns values in a single row of the list.
The row xml looks like this:

     <TextView android:id="@+id/text1"

     <TextView android:id="@+id/text2"

so I was thinking using simplecursoradapter which supposedly makes my
life easier by displaying the data in a list. However that is only
true if I want to display the raw data.
For the purpose of my program I need to do some computations on the
raw data sets, then display them. I am not sure how to do that using
SimpleCursorAdapter. Here's how I display the raw data:

       String[] from = new String[]

       int[] to = new int[]{,};

        // Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter records =
                    new SimpleCursorAdapter(this, R.layout.exset_row,
mExsetCursor, from, to);


Is there a way to do computation on the data in those rows before I
bind it with the SimpleCursorAdapter? I was trying to use an
alternative way of doing this by using arraylist and arrayadapter, but
that way I dont know to how achieve displaying 2 items in a single

This is my code for using arrayadapter which only display 1 text in a
row instead of 2 textviews in a row:

      //fill in the array
      timestamp_arr = new ArrayList<String>();
      type_arr = new ArrayList<String>();

      Log.d(TAG,"setting now in recordlist");
          setListAdapter(new ArrayAdapter<String>(this,
          setListAdapter(new ArrayAdapter<String>(this,

It's very obvious that it only displays one textview in a row because
I set the second arrayadapter overwrites the first one! I was trying
to use and for them, but it gave me some errors
04-23 01:40:58.658: ERROR/AndroidRuntime(3309):
android.content.res.Resources$NotFoundException: Resource ID
#0x7f070008 type #0x12 is not valid

I believe the second method can achieve this, but I'm not sure how do
deal with the layout problems, so if you any suggestions, please post
them out. Thank you!!


Computation on db data then list them using either SimpleCursorAdapter or ArrayAdapter

by skink » Fri, 23 Apr 2010 15:49:37 GMT


and override bindView method



Sponsored Links

Other Threads

1. Getting location data via wifi.

So I have just recently started programming for the Android.  I am
currently trying to get location data from a gpa and a network.  I've
noticed it's easy to use the DDMS emulator to send fake GPS data but I
cannot figure out how to do so with the wifi of the device.


2. Android emulator problems

So, I've been doing the android tutorials and every time I try to load
the emulator it gets to the waiting for HOME step and then cancels.
It will load the emulator, but it will only get to the screen with
ANDROID across.

I rebooted my computer redid the tutorials and cleaned the projects
and tried again.  This time it worked after a while, but when the
emulator actually loaded, my app wasnt on the device.

Can someone please help me out, I'm not sure if i messed up
configuring eclipse or what I'm doing wrong.  Thank you


3. Video code plays on one android device not on another.

4. Upgrade to Android 2.2

5. How to install ZIP files to Xperia X10

6. Ground or Tile overlays possible for Google Map ?

7. Accessing Phone Conversation Audio Stream