Android :: Moving Cursor Adapter Cursor Creation To Background Thread

Mar 29, 2010

The structure of some of my activities is a simple ListView with a custom CursorAdapter. The cursor is created in onCreate() on the activity from a SQLite database. The problem is that querying the SQLite database can be quite slow at times with lots of data (and let's assume I've already optimized the sql query as much as possible). Because it occurs in onCreate() on the UI thread, I get ugly black screens when opening the activity, which sometimes turn into ANRs, on a slow phone like the G1. I want to load the cursor in a background and show "Loading.." on screen while doing so. I saw AsyncQueryHandler used extensively in the framework, but this seems a solution geared more towards Content Providers and not application-local SQLite databases. I then thought of trying to load the cursor in a background thread, but realize that this might be problematic, as the CursorAdapter should be instantiated in onCreate() and should take a cursor as a parameter. The latest thought I had was to instantiate an empty MatrixCursor in onCreate() and pass that to the cursor adapter, while kicking off a thread/TimerTask to query the database. Then, on database cursor load, call cursorAdapter.change Cursor to the properly filled cursor. This doesn't seem very elegant and seems quite wasteful, however.

Android :: Moving Cursor Adapter cursor creation to background thread


Android :: An IF Statement In A Cursor Adapter?

Jul 15, 2010

CODE:...........................

View 1 Replies View Related

Android :: Cursor Adapter With Multi Select

Nov 11, 2010

I've written an APP the uses has a small SQL lite DB and using a cursor adapter I can retrieve the records and populate a list view with them. from there I can get the Id of a selected item and delete it from the DB which works great. the issue I have is that as the DB grows deleting one row at a time would be slow and frustrating so I wanted to know if there was any way to allow multiple selections possibly with check boxes or by even changing the text color of the items selected so that I can retreiving their relative ID's.

I have read some posts that talk about custom cursor adapters but I am not sure how to adapt them to my code.

I have posted my code below.

CODE:.........................

View 1 Replies View Related

Android :: Janky Custom Cursor Adapter

May 25, 2010

I have a Custom Cursor Adapter. It shows a list of installed applications with an icon, name and checkbox on each line item. I cache the list of applications in a database for faster retrieve and to store the state of the checkbox. However, I can't store the application icon in the db because sqlite doesn't support blobs. They list works rather well except that it is "janky" as described by Brad Fitzpatrick at Google IO (https://wave.google.com/wave/waveref/ googlewave.com/w+3kgmObZwO ). I'm trying to make my app non-janky by following the tutorial here: [url]... but I'm having trouble.

The reason my list is janky is because I look up each icon as you scroll down the list. drawable = pm.getApplicationIcon(c.getString(c.getColumnIndex(SmartLockDbAdapter.KEY_P­ACKAGE)));

getApplicationIcon takes too long to return to make for a smooth scrolling list. I would like to perform the action in the background with an AsyncTask but because bindView gets called repeatedly in a short time span, my icons end up with the wrong list item. I need help.

I've posted my whole ListActivity below in hopes that it helps other people. It's much harder to find an example of a working CursorAdapter then it is an ArrayAdapter.

CODE:........................

View 4 Replies View Related

Android :: Join ContentResolver Cursor With A Database Cursor

Mar 21, 2010

I get records from the system by quering a ContentResolver. I maintain the order of the items in the database. So I want to display the items in the order taken from my database.

How do I merge these two informations?

I am looking after an alternative way now. As what I ideally want is:

Get order of contacts by a custom order held in my database (this involves joining CR with my DB cursor, and doing an order by, later seams it's not possible with CursorJoiner) but there is more, if the join is not unique I want to sort by contact's name as last measure

Which is impossible using Cursor and Joiners, because of the missing feature of order bys, also I need to return a Cursor, as I will be using the in an ExpandableList

Also this translated to TSQL it would look like

select * from contactsdata
left join category on contactsdata.catid=category.id
order by category.pos asc, contact.display_name asc

So I am looking now after an alternative. I have in mind to load in a temporary DB table all data from CR, then do the query on the temporary table where I can join tables and do order bys? How does this sound to you?

View 1 Replies View Related

Android :: How To Use Simple Cursor Adapter To Include Button?

Jun 9, 2009

I have read the Gallery2.java example, which show how to map a Column's value to an element in the view I want to create (in this case, it maps 'NAME' to text1 element0. But what if I have a Button in my view, how can I know which Person is being clicked? or how can I query the person's info when a button in the new is clicked?

From the Gallery2.java example:
SpinnerAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_gallery_item,
// Give the cursor to the list adatper c,
// Map the NAME column in the people database to...
new String[] {People.NAME},
// The "text1" view defined in the XML template
new int[] { android.R.id.text1 });
Gallery g = (Gallery) findViewById(R.id.gallery);

View 2 Replies View Related

Android :: Is It Worth Writing A ContentProvider - Using Cursor Adapter?

Sep 14, 2010

We are connecting to a number of WebServices and fetching a lot of structured data(XML). We are parsing this data and storing them into SQLite tables. This part of the application runs periodically in the back ground.

On the foreground, the data fetched is displayed in ListViews. We have used ArrayAdapter to back these lists up. The thing is, every time the Actvity starts or data set is refreshed, we have to load the ArrayLists by querying the database and call notifyDataSetChanged() on the Adapter. This slows down the application and affects the User experience.

Question: 1. I'd imagine using a CursorAdapter might result in performance gain, since the framework will take care of managing the cursor. Is this assumption valid? 2. Will the CursorAdapter take care of reflecting updates to the database on the screen automatically? 3. Will I have to write a ContentProvider if I choose to use CursorAdapters? 4. Are there any other considerations that we need to make?

View 6 Replies View Related

Android :: Trying To Write Custom Adapter For Database Cursor

Jun 29, 2009

I been using custom adapters based on the BaseAdapter and I usually populate my data at the getView() funtion.

Now I'm trying to write my custom adapter for my database cursor which now will be based on a CursorAdapter.

I'm getting confused where I should do the populating work? Along with how do I implement my inflating and populating "smart/efficient code based on RomainGuy presentation."

View 8 Replies View Related

Android :: Causes A Redundant Cursor Adapter To View Copy

Oct 28, 2009

CursorAdapter is great, i'm a big fan. I notice that both newView() and bindView() are passed Cursors, indicating that extracting stuff from the Cursor and sticking it in the view should happen inside those overrides.

however in the source for CursorAdapter.getView() i see that bindView() gets called whether the view is recycled or not. in the new view case, this causes a redundant Cursor to View copy.

IMHO, CursorAdapter should call newView() if the view couldn't be recycled, or bindView() if it could.

View 3 Replies View Related

Android :: List View Separators Using A Cursor Adapter

Oct 5, 2010

I have a ListView which is populated using a CursorAdapter. I'd also like to have some separators in my ListView. I have accomplished this with an ArrayAdapter, but I'm not sure how to accomplish this with a CursorAdapter. Are there any strategies for doing so? Or am I out of luck?

View 1 Replies View Related

Android :: How To Only Show Specific Elements In A Cursor Adapter

Jul 23, 2010

I have a custom CursorAdapter that is taking items from a database and displaying them in a listview. If possible, I would like to display only certain elements based on some boolean value within a database element. Here is something similar to what I would like to do:

package itp.uts.program;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;
//Adapter tests if an element is read or unread, and bolds the items that are unread
public class BoldAdapter extends CursorAdapter. Code...

View 2 Replies View Related

Android :: Simple Cursor Adapter - List View

Jun 9, 2010

I have table with 3 columns which is binded to an XML document with three text views.

CODE:........

Depending on the value store in the third column, I have to decide whether i should display this row or not

How should, I go about with this.

This is what I have so far :

CODE:...............

View 2 Replies View Related

Android : Binded Spinner Widget - Cursor Adapter?

Aug 24, 2009

I successfully binded a spinner widget to a simple cursor adapter, but I started having problems when I tried to add a new item to the table which feeds the spinner by clicking an "add new item" button. The idea was to launch a new activity which returns the rowid of the just added element, and use it to set the new position.

What I basically did is to implement something like:

break; in the "onActivityResult" method, the rowid has the correct value but setSelection has no effect. I also tried to force the argument to some other values, but still with no result. If I call it in the onCreate method, it works beautifully. Moreover, I am still not sure that setSelection is the right method to call, since its arg is named "position" in the doc, while I am passing an "id".

View 2 Replies View Related

Android :: Moving Cursor Position To A Certain ID

Sep 23, 2010

My user can flick through a set of records.I save the last seen record _ID in Preferences, so that they can start off from where they left when they access the application next time.The cursor that I have extracts _ID field too.However, I don't know how to move cursor to that particular row.The following functions of the cursor need a specific position to go to :- The _ID may not be sequential (due to deletes etc).Any way to do this?

View 1 Replies View Related

Android :: Photo URI Of Contact Image - Using With Simple Cursor Adapter

Apr 8, 2010

I want to write a short app for getting some info from contacts, the first list screen I have should display the user Image (or an Image from resources if no such image exists) an the user display name. The problem is I don't seem to find a query that will provide me with the display name and a user id And the image URI in the same query. Moreover I'm aware of the fact that if the user has no image and the URI is empty or null i will most likely to get an exception while the adapter calls setViewImage(). Is there a simple way around it or should I override the setViewImage() or bindView() methods?

Also about the query, any chance I can make a single query for contact URI, _ID, contact_id and display name? my current queries: To get the contacts:
private Cursor getContacts() { Uri uri = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[] ContactsContract.Data._ID,ContactsContract.Data.CONTACT_ID,
ContactsContract.Data.DISPLAY_NAME };
String selection = ContactsContract.Data.MIMETYPE + " = ?";
String[] selectionArgs = {ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder); }

If I have a contact id and want the image:
int _id = m_cursor.getColumnIndex(ContactsContract.Contacts._ID);
//try to retrieve the photo, if exists.
Uri photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
m_cursor.getLong(_id)); InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(m_context.getContentResolver(), photoUri);
Here I get from a cursor with _ID column the id and then creating the uri, I know I can get a row number but I'm not familiar enough with contentProvider to know how to join tables to get it all in one query (if even possible).

View 2 Replies View Related

Android :: Cursor Adapter Making My Display Choppy - When I Scroll

Jul 26, 2010

can anyone tell me what im doing wrong with my cursorAdapter? its making my display choppy when i scroll. I used to have it within a getview but was ripped (rightfully so) on IRC several times because thats not the right place for it. Im still learning and just trying to correctly wrap my head around things.

http://pastebin.com/Dc5ppHUM

View 3 Replies View Related

Android :: Add Childs To My Custom View Group With A Cursor Adapter?

Oct 13, 2010

I've got a schedule Class, which is simply a custom ViewGroup (with custom onMeasure() and onLayout()), which enables me to place childs(=events) with LayoutParams for column/row start and column/row end. The number of childs and their LayoutParams depend on database entries.

Now I'm trying to add childs (events) from my database. I'd have to use a Cursor Adapter, so my schedule Class has to extend ListView, right? I tried that but the newView() method of the adapter is never called. Why not? My custom ListView doesn't ask the adapter for childs, no childs are added. I also can't add the childs by hand calling schedule.addView() if I extend from AdapterView.

How can I add events to the schedule with the data from the cursor?

View 1 Replies View Related

Android :: Cursor Adapter - Binding Multiple Item Values In ListView

Jan 12, 2010

I have the following code to intantiate a SimpleCursorAdapter to use with a ListView. As you can see I have passed the R.layout.log_item to display the list items, and one value/control to bind to (TripDate).

SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.log_item,c,new String[] {DBAdapter.KEY_LOG_TRIPDATE},new int[]{R.id.txtTripDate});

This works. I currently only have one widget in the layout xml, a TextView to hold the TripDate.
How do I pass multiple binding parameters for the additional widgets in the layout? So I can also display other info.

View 1 Replies View Related

Android :: Proper Implementation Of Changing ListView Data With Cursor Adapter

Sep 3, 2010

I have a ListView populated via a CursorAdapter. I give my user the ability to alter the data in the list. For example, the user can mark a row as being unread (the data are messages).

Suppose my user marked a row unread. Would a proper implementation mark the row in the database as read and then requery the Cursor?

View 1 Replies View Related

Android :: Droid Save Checkbox State In ListView With Cursor Adapter

Mar 9, 2010

I cant find a way to save the checkbox state when using a Cursor adapter. Everything else works fine but if i click on a checkbox it is repeated when it is recycled. Ive seen examples using array adapters but because of my lack of experience im finding it hard to translate it into using a cursor adapter. Could someone give me an example of how to go about it.code...

View 3 Replies View Related

Android :: Implementing Filterable Cursor Adapter - How To Invoke/refresh Filter

Jun 15, 2010

I've overriden runQueryOnBackgroundThread and done what I've needed to do for the corrent query to be excuted with a given constraint. My current challenge is figuring out how to actually pass in the constraint. I've got an ActivityList which I'd like to filter on a stored preference. I'm thinking I will need to perform a filter during onStart such that the most recent preference changes are picked up. All that is in place, just not clicking on how I'd actually cause the filter to happen!

View 2 Replies View Related

Android :: Contents Of List View - Using A Cursor Adapter - Are Not Updated Refreshed

Aug 26, 2010

I have a list which shows data from a database using a cursor adapter. Using Menu option I am updating my database (inserting more rows deleting existing rows). When Menu operation completes, I want contents of list should show updated contents.

I have tried using cursor.requery(); (or explicitly querying cursor again) and using adapter.notifydatasetchanged(), but with this list of contents are not updated.

How can I refresh the contents of the list.

View 2 Replies View Related

Android :: Simple Cursor Adapter - List View - Binded To XML Document With Three Text Views

Mar 18, 2009

I have table with 3 columns which is binded to an XML document with three text views.

CODE:........

Depending on the value store in the third column, I want to change the text color in R.id.c. How should, I go about with this.

This is what I have so far :

COD:...............

View 3 Replies View Related

Android :: Modifying Adapter Content From Background Thread

Sep 14, 2010

I've read up quite a bit on the exception thrown while using BaseAdapter, but i can't seem to find an alternative solution: Make sure the content of your adapter is not modified from a background thread. What i want to achieve is to keep a copy of a message queue in memory, and use this message queue to populate the BaseAdapter for my ListView. The reason im doing this is that the message queue will keep getting messages from a socket even when the ListView is not currently present (for example a chat window).

The problem comes when i have the Activity with the ListView in foreground, BaseAdapter binded to the message queue's data, and a message comes in the socket. Adding the new message into the queue will throw the exception mentioned above. Unless i pre-populate my BaseAdapter with the message queue (as in the BaseAdapter having its own message queue) and updating both of them when a new message come in, i can't really find a way around this issue. I don't really want to double up the effort on keeping those 2 queues up-to-date like this, surely there is a better way of doing this? Send broadcasts around doesn't work either because of the potential delay in the adapter serving a scroll and the notifyDataSetChanged call is made.

View 1 Replies View Related

Android :: Finalizing Cursor Android.database.sqlite.SQLite­Cursor

May 6, 2009

I am seeing the exception in 'adb logcat'.But I don't know if it is caused by my application or android platform.Can you please give me any idea how to troubleshoot this exception?

View 3 Replies View Related

Android :: Row ID From A Cursor

May 17, 2010

How do I get the row ID from a Cursor?

View 2 Replies View Related

Android :: DB Cursor Not Working

Oct 18, 2009

I've got this piece of code where I count words in a dictionary and then I try to query them:

CODE:.............

The SELECT_BY_LENGTH is defined this way: private static final String SELECT_BY_LENGTH = "select word._id, word.word from word where length(word.word) between ? and ? ";

And the count works perfectly but the cursor.move(1) always returns false. I've tried to get the column count and responds with the correct count and the column names map too. I mean that the method getColumnIndex works too but I can't get any data from the cursor. All such methods fail. Am I doin' something wrong? I'm using android 1.5.

View 5 Replies View Related

Android :: Update A Cursor

Apr 24, 2009

I call ContentResolver's query method to get a Cursor, and I would like to update the title of that row to 'new title' how to do it?

CODE:...................

View 4 Replies View Related

Android :: Cursor And RowId

May 17, 2010

How do get the row ID from a Cursor?

View 5 Replies View Related

Android :: Get URL From Cursor Object

Jun 16, 2009

I have a Cursor points to a Contact. How can I get an url built from that Cursor?

I need to know that because from here: http://developer.android.com/guide/topics/providers/content-providers.html

I need to have an url so that I can build a phone uri, like this: phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);

and I can query all the phone numbers for that contact.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved