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
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.
View 10 Replies
View Related
Jul 15, 2010
CODE:...........................
View 1 Replies
View Related
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
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_PACKAGE)));
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
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
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
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
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
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
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
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
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
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
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
Aug 5, 2010
Can you use the optical trackpad to move the cursor when writing text? So if you realise you've gone wrong you don't have to place your finger in-between two letters. On my existing very old touch scree phone this is a big issue as i can never get the cursor exactly where i want Another trackpad question - what purpose does it have when browsing, does it highlight links allowing quick navigation without using the pinch and zoom?
Final track pad question- do you use it? The battery- with moderate to heavy use will it ALWAYS last a long day 7-11 for example? Hows the froyo update, is sense still as smooth as ever?
View 12 Replies
View Related
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
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
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
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
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
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
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
Mar 21, 2010
Just curious for an opinion or two I've been tempted to download Open Home from Better Android because of all their cool icons, skins, and other things. At the same time, I see comments about it slowing down the phone significantly or causing all sorts of forced closes, etc.Are most people using and liking Better Android apps? I've got an HTC Dream, so I'm on the old operating system. Not sure if that makes a difference.
View 4 Replies
View Related
Aug 26, 2010
so I wanted to get an Evo, but then I saw all these graphic tests and found The EPIC to have amazing GPU. Now I really like the evo for htc sense, bigger screen and looks. But I want the epic for its GPU. I dont care much for the keyboard. Im afraid the GPU on evo will be outdated and not run games anymore. Im afraid cuz my cousin got a Moment and he cant run any of the good 3d games, i got my pre before him and I can run better 3d games then him.Should I get the epic just for the GPU? Do you guys even see android gaming taking off and using the epic's internals or will the GPU of EVO(Adreno 200) be fine for current and future android games. As I see it, most devs are using the N1 to develop on, so im guessing the GPU in the evo should be fine right? or should I be safe and get the Epic GPU and be able to use the keyboard for gaming, but not be satisfied by looks? (maybe when i use it in person ill fine in love with the looks lol)SHORT VERSION Should i get the EVO and not be worried about highend 3d games sucking/being laggy? Is the GPU on the Evo good enough because it is the current standard for 3d games? Dont most developers develop on n1, thus the Evo gpu will be perfect? Also I think A lot of developers are optimizing games for the snapdragons. is any of this true?
View 6 Replies
View Related
Sep 9, 2010
Does anyone know if Qik is working on a cleaner version of Qik for Evo? I find it almost unuseable even when both phones are on Wifi in the conversation. Is the premium version worth buying as it mentions higher resolution.
View 2 Replies
View Related
Jul 14, 2010
I've been enjoying my evo so far with one huge complaint. I don't think wimax 4g is even worth having right now. First it is a battery hog, and second building penetration is terrible....i stay on wifi most of the time but when I do turn 4g it just doesn't am practical. Another thing is that sprint is really advertising this as a 4g phone but for the normal customer I would think they would beupset that their signal isn't reliable...well the point of this thread its to see how everybody else feels about wimax. And for those who want to call me a troll you can check my history.
View 44 Replies
View Related
Sep 23, 2010
I have tazz 7 currently and up until now I have never wiped because it was not required. So is the jump from 7 to 8 worth the effort of backing up. I use astro because it is faster than the free version of titanium and froyo never seems to reload all of my apps for some reason.
View 5 Replies
View Related
Nov 15, 2010
I just downloaded the trial version of Poweramp and it looks really cool. But before I pay for it I was wondering if it was worth the money or is there a free music player that is better or as cool as Poweramp?
View 8 Replies
View Related
Aug 11, 2010
I could easy sell my droid for 160-180 and i could get the new droid 2 for about 150 give or take taxes or what not.my droid 1 is rooted and i love it is it worth to upgrade to the new droid 2 for the more memory and newer processor
View 4 Replies
View Related