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"
         android:textSize="16sp"
         android:textStyle="bold"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"/>

     <TextView android:id="@+id/text2"
         android:textSize="14sp"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"/>

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[]
{BtDbAdapter.KEY_EX_TYPE,BtDbAdapter.KEY_EX_TIMESTAMP};

       int[] to = new int[]{R.id.text1, R.id.text2};

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

        setListAdapter(records);

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
row.

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>();
      fillRecord();

      Log.d(TAG,"setting now in recordlist");
          setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_item,timestamp_arr));
          setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_item2,type_arr));

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 R.id.text1 and R.id.text2 for them, but it gave me some errors
saying
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


 


use 
 http://developer.android.com/intl/fr/reference/android/widget/ResourceCursorAdapter.html 
and override bindView method

pskink

--


Sponsored Links


Other Threads

1. opengl display issue when using g.getHolder().setFormat(PixelFormat.RGBA_8888);

Ok, so I wanted to create a transparent activity where I draw some
cubes on the screen.  Well I initially was developing with the default
settings where
  g.getHolder().setFormat(PixelFormat.RGBA_8888);
my view in a real narrow scope see below code for sample.

when not setting a alpha channel. it works as expected.

when using
  g.getHolder().setFormat(PixelFormat.RGBA_8888);
it causes me to zoom way out where my objects are really really small
like 1/80th the screen AND i end up with dual view.  where the screen
is divided evenly in two where the objects are drawn two times in each
view.

whats going on?

CODE...

//i write directly to my actvitiy my surface view not using a
layout.xml file
g =new MySurfaceView(this,this.ballContext);
                g.setFocusable(true);
                v = g;
                setContentView((View)v);
                // Use a surface format with an Alpha channel:
        g.getHolder().setFormat(PixelFormat.RGBA_8888);

when i glu my look at
GLU.gluLookAt(gl, 0, 0, 3,0,0,0, 0,1,0);

and my objects get drawn at a -7 depth into the screen.  so not very
far away. they are maybe 1/8 the screen when not using the alpha
format
float zOffset = -7.0f;

initial gl set up
               gl.glEnable(GL10.GL_LIGHTING);
                gl.glEnable(GL10.GL_LIGHT0);
                gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, 
matAmbient,
0);
                gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, 
matDiffuse,
0);

                gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient,     
0);
                gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse,     
0);
                gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);

                gl.glEnable(GL10.GL_DEPTH_TEST);
                gl.glDepthFunc(GL10.GL_LEQUAL);

                gl.glEnable(GL10.GL_TEXTURE_2D);

                gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                gl.glClearDepthf(1.0f);

                gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff);
                gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
                gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
                gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

                gl.glEnable(GL10.GL_CULL_FACE);
                gl.glShadeModel(GL10.GL_SMOOTH);
--~--~---------~--~----~------------~-------~--~----~

2. Creditcard chargeback

So I got a creditcard chargeback on my account today.  Not only does
it refund the purchase but Google charges me a $3.00 fine, which
effectively negates a second purchase of my app as well.  This
customer never contacted me with a problem and never asked for a
refund.  Their transaction was over a month ago and went perfectly
smoothly.  Then, out of the blue, Google charges me $3.00 and even
spells out that I have no recourse in the matter.

This can happen to any of us anytime and as the hard-working
developers we have absolutely no defense against it.  By any
reasonable logic I didn't do anything wrong, think about it.  It's
just stealing from me plain and simple.  There is no other way to
describe what happened.  I was stolen from, period.

Yeah, it's the TOS.  So what?  That makes it okay?  Random unjustified
fines and fees when I haven't do anything wrong?  Come on, TOS makes
it legal, by no means does it make it ethical!

Just to point out, this is the kind of stuff that motivated me to
never go anywhere near the iPhone.  Now I have to deal with it with
Android as well?  I really expected better.

It could happen to you, tomorrow, out of the blue.  Just wait, just
see.

If anyone knows of any way to dispute this or any way to defend
against it, if anyone here works for Google and knows who I should
contact, please share!  I have no ideas at all about what to do about
this.


--~--~---------~--~----~------------~-------~--~----~

3. Proper usage of object passing for TabActivity/TabHost

4. Help is needed to use the beagleboard as a USB device

5. Cross process cursor using AbstractWindowedCursor

6. Smooth scrolling in surfaceview possible?

7. Get the currently selected file through a service.