Android :: Add Extra Elements Into Cursor Or SimpleCursorAdapter?
Jan 31, 2009
Suppose I get a cursor that contains all rows from my database, and I want to show them on a spinner, the following code will work. But I want to show two extra items as the spinner elements, how can I add those two elements?
For example, if the following code can show 4 spinner elements "Orange" "Apple" "Cabbage" "Green Onion", how can I add an element in the spinner saying "All fruit" "All Vegetable"?
CODE:....................
View 2 Replies
Jul 19, 2010
If I pass a cursor to a simplecursoradapter, do I still need to close the cursor? if so when: after I pass it to the adapter or when the adapter is finished?
View 2 Replies
View Related
Jun 8, 2010
I have an android list activity that is backed by a database cursor through a SimpleCursorAdapter.
i have one constraint that need to be modify the cursor data. i cannot add the constraint in query.
How should I be update cursor ?
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
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
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
Jun 25, 2009
I am trying to pull data from a cursor which is initialized as follows:
Uri inboxUri = Uri.parse("content://sms/"); Cursor c = managedQuery(inboxUri, null, null, null, null);
This effectively gets me to latest text message that has been sent/ received. I am now trying to put certain fields into a listView, but need to format them before displaying them. The date is represented in the table in milliseconds and I want to convert it to a date before placing it in the list.
Here is where I am trying to place the date in my list. How can I format these fields before placing them into my listview?
CODE:.......................
View 2 Replies
View Related
Apr 27, 2010
I'm having problems with spinner. I'm using spinner that is bound to a SimpleCursorAdapter. I want to retrieve the text value of the selected item. So i tried
CODE:..................
View 2 Replies
View Related
Apr 14, 2009
I am trying to connect a AutoCompleteTextView with a SimpleCursorAdapter, which narrows down the selection of a list of words, when the user starts typing.
Following some other posts here, I've come up with the following code, but it doesn't work. I defined a FilterQueryProvider runQuery() method for the SimpleCursor Adapter, but when I use the debugger in the code, the response from the ContentResolver.query((0 method call is null.
I think the problem is that there is no relationship between the CONTENT_URI and the SQL database, but I can't be sure.
CODE:.......................
View 2 Replies
View Related
Mar 24, 2009
The favicon field returned by the browser bookmark provider is a sqlite blob. I want to display the bookmarks in a listview with the favicon but couldn't find a way to do it. I tried using a SimpleCursorAdapter.ViewBinder but I get an exception.
This is what my code looks like :
CODE:...................
View 5 Replies
View Related
Apr 8, 2009
I have an application that involves reading a text dictionary file with about 7000 entries, and allowing the user to choose one of these. My first approach was to allow the user to select one of these by using a AutoCompleteTextView together with ArrayAdapter<String>. This works, but is very slow (~10 seconds to update the word list each time the user enters a character to narrow down the choice).
I was wondering how to rework it so that I could use a database using a SimpleCursorAdapter instead. In other words, to hope that a SQL database could provide a more efficient ordering and access for the elements. Is this the best way to do it? I've also seen several references to SQLiteDatabase, but don't know which one to use.
I found this code fragmant consisting of an extended SimpleAdapter. http://sacoskun.blogspot.com/2008/08...leadapter.html<http://sacoskun.blogspot.com/2008/08/autocompletetextview-with-simple...>
Unfortunately, this is not a complete worked out example. Could someone forward me a more complete example? I've found lots of code fragments, but no code that shows how to initialise the SimpleCursorAdapter contents, or how it works together with the AutoCompleteTextView.
View 3 Replies
View Related
Apr 1, 2010
I want to create a table whose primary key will be some other field and not _id . The below table gets created but the value of _id remains null :
"create table accounts ("+BaseColumns._ID+" integer , profile_name text primary key" +" name text not null);";
My doubt is wont _id get auto incremented if we do not place "+BaseColumns._ID integer primary key autoincrement+" .
View 3 Replies
View Related
Oct 22, 2009
I have a problem with bindView() that has me puzzled. I am using it to customize each row, including setting icons, coloring the background and setting up listeners for buttons. It mostly works as expected, but not quite.
When I fill the ListView with SimpleCursorAdapter, I get multiple calls to bindView() for position 0, but only 1 call for the other rows. The problem is that when all is said and done, I have 2 rows (LinearLayout) created for position 0. Here is a sample log extract:
CODE:........
I use a view holder class to hold the view, position and other data so that when a button is clicked, I can retrieve the holder with view.getParent.getTag(). This all works fine. The problem is that there are two views for position 0, but it's the first one in the above logcat that seems to be displayed. My code which acts on the rows when a button is clicked (especially setting background color) does not reliably hit the position 0 row that is actually displayed.
I can see what's happening but I am at a loss about what to do about it. Why are two view created for position 0? Is it something that I can control? How? If not, how should I deal with it so that the results when I modify the views are predictable?
View 5 Replies
View Related
Feb 27, 2010
Since the query that comprises my ListView basically gets the rowID, name, and a third column from my databases's table, I want to be able to filter the cursor based on the partial value of the name column. However, I am uncertain of whether I can do this directly from runQuery without expanding my DB class since I want to filter the existing cursor, or will I have to create a new query function in my DB class that partially searches my name column, and if so, how would I go about creating the query statement while using the CharSequence constraint argument in runQuery?I am also concerned about the performance issues associated with trying to run multiple queries based on partial text since the DB table in question has about 1300-1400 rows. In other words, would I run into a bottleneck trying to filter the cursor?
View 1 Replies
View Related
Mar 19, 2010
The problem is as follows: - My app is deriving from TabActivity that has 3 tabs - Each tab has a ListView - Tab1 is populated by an adapter that inherit SimpleCursorAdapter and overrided the bindView() method. This tab is displaying correctly. - Tab 2 is also populated by another adatper that inherit SimpleCursorAdapter and overrided the bindView() method. For some reason that I don't understand, the overrided bindView() is not being called. Thus the tab is not displaying correctly.
Here's my code fragment:
CODE:...........................
View 3 Replies
View Related
Oct 31, 2010
Im using the NotePad example as a base for an application. This binds a ListActivity to a Provider.
Its perfect, except it uses SimpleCursorAdaptor, which means the list only binds to and displays one item per row. I want it to display two items, both bound the Provider. Or more accurately display the text from one Content Provider field and an icon which depends on the value of a different field.
This sounds like a pretty simple thing to do, a very slight modification to the NotePad application. Trouble is, I have no idea on *how* to do it. I really need a starting point, and "approach" to use.
So far I have tried (unsuccessfully):
* Hand populating the ListView by reading in the Provider data and populating an array in OnCreate. This works, except as the data is not bound the List does not update when I add an item.
* Extending SimpleCursorAdapter with a custom getViewBinder. Could still only bind to a single column.
* Building my own ListAdaptor. Couldn't get this to work.
* Concatenating both fileds together and "parsing" 2 fields into 1 field read/write.
The next thing I will try is extremely tacky running two separate simpleCursorAdaptors in two views in a Linear Layout, fudged so the row height is identical, and duplicate the logic.
I say this only to show that I really, really have tried.
How I can create a custom CursorAdaptor which binds to two fields instead of just one like SimpleCursorAdapter?
View 4 Replies
View Related
Nov 23, 2009
I was poking around in the documentation for the simpleCursorAdapter and I read that if the simpleCursorAdapter doesn't identify your images as resources it will assume they are URIs. My question is how do i retrieve the URI for an image placed into the asset folder of my application?
View 8 Replies
View Related
Nov 24, 2010
I know you can set fastScroll for listViews, but currently I would like to use a ListActivity with a simplecursoradapter instead. Is there no way to make such a view fast scroll?
View 1 Replies
View Related
Jul 23, 2010
I'm getting some very jerky scrolling while using the code below to create a ListView from a Cursor. Is there something I'm doing wrong, or any way to improve the performance of this ListView?
CODE:.............
Note: bookmarkStore.getCursor() returns an unmanaged cursor from a sqlite database containing the columns from bookmarksColumns.
View 7 Replies
View Related
Jul 26, 2010
With the below code, nothing appears in the ListActivity as I would expect.
No errors are shown in logcat.
CODE:..............
View 1 Replies
View Related
Sep 6, 2010
I've got a class that creates a list from a DB using SimpleCursorAdapter. I want to add an onClick event to each item in the list but I don't know where to place the code.
View 1 Replies
View Related
Jul 20, 2010
I cant figure out how to perform an onClick on my ListAdapter.
Here is my code:
CODE:.....................
I want to be able to click on an item from the database, then go into a view that only contains info for that item. My class currently extends ListActivity. I've tried OnItemClickListener, but I dont know what else to use to make it work.
View 1 Replies
View Related
Mar 8, 2010
I'm trying to change the content of a row in ListView programmatically. In one row there are 3 TextView and a ProgressBar. I want to animate the ProgressBar if the 'result' column of the current row is zero.
After reading some tutorials and docs, I came to the conclusion that LayoutInflater has to be used and getView() - overriden. Maybe I am wrong on this. code...
View 1 Replies
View Related
Jan 4, 2010
I have a ListView that is backed by a SimpleCursorAdapter. I'd like to be able to filter the list like you would a contacts list, just by typing, and I came across the textFilterEnabled() Problem is, I couldn't see how to get it to work with a SimpleCursorAdapter. Is this even possible?
View 1 Replies
View Related
Apr 23, 2010
I juststarted programming in android a few weeks ago, so I am not entirely sure how to deal with listing values. 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:
CODE:...............
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:
CODE:.........
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:
CODE:.......
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.
View 2 Replies
View Related
Nov 4, 2010
I've been scouring throug the examples and tutorials but I can't seem to get my head around how to handle recycling within a subclassed SimpleCursorAdapter. I know that for regular ArrayAdapters you can check convertView for null and inflate if null from the xml and if not null, recycle, but I'm having a little trouble visualizing how that works with the from and to arrays within the SimpleCursorAdapter subclass. I tried to figure this out from the The Busy Coders Guide to Android Development by Commonsware but was unsuccessful. If anyone knows of any tips, examples, or tutorials, I would be grateful to see them.
View 2 Replies
View Related
May 18, 2010
I have this scenario
onResume of an activity:
CODE:............
Adapter has been defined as:
CODE:.............
And the onContentChanged event is not fired, although the onResume and the call to the adapter is issued.
View 1 Replies
View Related
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
Dec 8, 2013
My app is mainly made up of a listview linked to a simplecursoradapter (custom one I might add) which in turn uses a cursor which gets the data fed in from a dbadapter class.
using the dbadapter class I can retrieve data using the rawquery and query methods no problem. However I am trying to allow the user to enter a month in and then the app will scroll to that month in the list , instead of the user having to scroll through several months to get there.
This is where I am struggling, I have tried to move to the position within the original cursor and then calling changeCursor from the simplecursoradapter with no luck and tried using the listview with smothscrolltoposition again with no luck and even tried to notifydatachangedset (probably got that named wrong) and then within the custom simplecursoradater try and move to it but that does not work either.
View 1 Replies
View Related
Nov 10, 2010
I'm trying to modify two TextViews in exactly the same way. I thought I can give them same id and with findViewById() and setText() methods change those TextViews in two lines. But it seems only one TextView is changed.Is there a way to do this?Or I have to make different ids for every element, get every element by findViewById() method and set it's text?
View 3 Replies
View Related