Hard to describe ... How to quickly scan through all rows?! How to pass a cursor between two activities?!

by Mariano Kamp » Sat, 10 Apr 2010 01:51:28 GMT


Sponsored Links
 Hi,

  I have an app that has a list view of messages and a detail view. If you
click on a message in the list view the detail view is opened for the
message in the row you clicked on.
In the detail view you also can go back and forth to other messages. So I
pass in the position of the row the user clicked on and the criteria I need
to rebuild the cursor like I did for the list. Then I use
Cursor.moveToPosition() to get to the selected row.

  So far so good. There is only one issue, when an import is running in the
background that inserts new (or deletes aged) messages then between the time
of the click and the time the detail view queries the database again it
maybe that the position is not valid anymore.

  Any idea how to deal with that?

  I tried to pass in a key instead and then go through all rows until I find
the one that has the same key, but this takes a real long time and doesn't
seem feasable at all. But maybe I am doing it wrong. It looks something like
this:

while (contentCursor.moveToNext()) {
   if (42 == contentCursor.getLong(0))
      break;
}

  Any better way to do that in general?

  I could try what happens when I pass in the position also and start from
there. Usually that should work and when it doesn't then I could scan all
messages?! The problem is, scanning all say 1,000 articles may take more
than 5 seconds on a G1.

Cheers,
Mariano

--



Other Threads

1. ListActivity.onListItemClick() only responds to trackball/dpad clicks

Hi,

I have been struggling for over two hours now getting a custom
ListActivity to respond to touch/click events directly on its list
items. However, onListItemClick() is only called when first focusing a
list element and then pressing the trackball or dpad-center button.

The odd thing is that it works in another custom ListActivity I
wrote... any general ideas when this can actually happen? I tried
playing around with the focusable und clickable attributes on all the
list entry views and the list view itself. I think I tried every
possible combination, but it never works.... it simply looks as if the
list items views are consuming the click event, so the list view never
gets to it, but then again, why would it work using the dpad then??

Any help greatly appreciated.

Best,
Matthias
--~--~---------~--~----~------------~-------~--~----~

2. How to get the current battery level of the device using an API call

Have you tried something like

int level = this.getIntent().getIntExtra("level", 0);
int scale = this.getIntent().getIntExtra("scale", 100);
if((level * 100 / scale) > 70){
// dl
}

monmonja
http://almondmendoza.com/2009/01/04/getting-battery-information-on-android/

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

3. Resolution problem while porting Android application on 2430

4. If the bluetooth is build as module not build in, where is better to insmod it

5. Gears geolocation on G1

6. How to control the SurfaceView's z-order

7. Implications of Using Non Standard Packages