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?

Android :: join ContentResolver Cursor with a Database Cursor


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.

View 10 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 :: How To Use Other External Cursor / Prepare By SQL Database?

Sep 21, 2009

In the API Demo, there is example on using Simple Cursor Adapter. However, it is using the MediaS tore cursor. Is there any method so that I can use other external cursor prepare by SQL database. I don't know what should I input to the from String.

View 2 Replies View Related

Android :: How To Import Cursor From Database Class Into Current One?

Jul 1, 2010

Here is my code for my db class:
package one.two;
import java.util.List;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import java.util.ArrayList;
public class DBAdapter extends ListActivity
{public String status = "status";
public String id = "id";
public String arrival = "arrival";
public String destination = "destination";
public String ferry = "ferry";
private static String DB_PATH = "/data/data/one.two/databases/";
private static final String DATABASE_NAME = "ferry.db";
private static final String DATABASE_TABLE = "port";
public static Context context;
public Cursor c;
public static SQLiteDatabase DbLib;
//overloaded non-null constructor
public DBAdapter(Context context) {
DbLib = context.openOrCreateDatabase(DATABASE_NAME,
SQLiteDatabase.CREATE_IF_NECESSARY,null);
System.out.println("OpenOrCreateDB Done");
} public class DatabaseHelper extends SQLiteOpenHelper {
Context context;
DatabaseHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}//end constructor DatabaseHelper
// ---closes the database---
public void close() {
DBHelper.close();
}//end close()
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion){
}//end onUpgrade()
@Override
public void onCreate(SQLiteDatabase db){
}//end onCreate()
}// end class DatabaseHelper
private static DatabaseHelper DBHelper;
private static final int DATABASE_VERSION = 1;
public static ArrayList<String> getAllTitles(){
ArrayList<String> port = new ArrayList<String>();
Cursor c=null;
c = DbLib.query("port"
new String[] { "status", "id", "arrival",
"destination", "ferry" }, null, null,
null, null, null);
try {
if (c!=null) { // start - when there is at least 1 record
System.out.println("Cursor is NOT NULL");
int i =0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{// Debug Stm
System.out.println("Record No. "+i);
System.out.println(c.getString(0));
System.out.println(c.getString(1));
System.out.println(c.getString(2));
System.out.println(c.getString(3));
System.out.println(c.getString(4));
// Assign database cursor.records to arraylist
port.add(i,c.getString(0));
port.add(i,c.getString(1));
port.add(i,c.getString(2));
port.add(i,c.getString(3));
port.add(i,c.getString(4));
i = i + 1;
} } // end - where there is at least 1 record
} finally {
if (c!=null) {
c.close();
} } return port;
}//end getAllTitles()
public void open() {
//Open the database
String myPath = DB_PATH + DATABASE_NAME;
DbLib = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} }//end class DBAdapter
My Arrival class
package one.two;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class Arrival extends ListActivity
{ private ListView listView;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{ ArrayList<String> retList = new ArrayList<String>();
System.out.println("Start onCreate Function");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("In onCreate Function");
System.out.println("In of GetData");
DBAdapter db = new DBAdapter(this);
System.out.println("DB Open");
db.open();
System.out.println("DB Opened");
retList = getData();
System.out.println("Out of GetData");
// force count no. of records in table
// dump to check index
int cnt = 2;
int i=0;
for (i = 0; i<cnt; i++)
System.out.println(retList.toString());
listView = (ListView) findViewById(android.R.id.list);
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.id.list, null, null, null);
this.setListAdapter(mAdapter);
// db.close();
} @SuppressWarnings("static-access")
public static ArrayList<String> getData()
{ ArrayList<String> items = DBAdapter.getAllTitles();
// titles ???? redundant
//ArrayList<String> titles = new ArrayList<String>(items);
System.out.println("Return a LIST titles");
return items;
} }

View 1 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 :: Populate A Spinner From Cursor Accessing An SQLite Database?

Aug 25, 2009

How do you populate a spinner from a cursor accessing an SQLite database?

View 2 Replies View Related

Android : Working With SQLite Database / Getting Cursor Out Of Bounds Exception

Jun 30, 2009

I am having some trouble working with the SQLite database. I am able to create the database, add to it, and delete from it with no problem by following the Notepad examples, but I am trying to avoid duplicates and therefore want to check to see if an entry exists already.

Below is the code I have for testing to see if a game exists. I get the correct Log message of "No Games" when there are no games, as well as the correct value for column from getColumnIndex which is proven to me by the log printout telling me that column = 1.

The error message that I receive if I don't catch the exception says "Caused by android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

Where is Index -1 being requested if my call to getColumnIndex is returning 1? Code...

View 3 Replies View Related

Android :: Android.database.StaleDataExce­ption Access Closed Cursor

May 18, 2010

I have activity A and I used managedQuery in Activity A. I have an adpater which extends from BaseAdapter. In GetView I access the mcursor to get fields.If I click a button on Activity A it goes to B, A---> B.The problem arises when I am in activity B *and it's visible(B), the error is thrown from Acitivity A.I dont understand why I get the error from Activity A. Activity B is visible now and A is in background.There was a post already on this group with similar error but there was no response.I was hoping if someone encountered this and found a solution.

View 2 Replies View Related

Android :: Open Helper To Open Database And Get A Cursor To Pass To CursorAdapter

Jul 1, 2010

I have a ListActivity that uses a CursorAdapter to fill the rows in the view. I wrote a database helper class that gives me back results for common queries I make for my app, and it uses an SQLiteOpenHelper implementation I wrote to open the database. I use the open helper to open the database and get a cursor to pass to my CursorAdapter.

Here's a code snippet:

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

The problem I'm having, that I didn't have before I implemented the open helper (before I just opened the database directly without a helper), is when I click on an item, which takes me to another activity, and then go back to this activity. When it initializes everything is fine, and my list is populated fine, but when I go back from the activity that follows, the list is empty and in the LogCat I see "Invalid statement in fillWindow()".

It appears from a few post I've seen that the reason is, when I requery the cursor, the database is closed. But I'm not closing it! I'm scratching my head on this one.

View 2 Replies View Related

Android : Adding A "column" - Data To A Database Cursor

Jan 10, 2010

Maybe I'm going about this the wrong way, but if so, please correct me. Here is the situation: I have a query which returns URI strings for ringtones stored in a database.

I am trying to add a "column" to this cursor with the ringer "Title" (since this can change outside my program). I can successfully user RingtoneManager to get the title, but I cannot figure out how to add this "column" to the cursor data for later use. Here is what I have so far: Code...

View 2 Replies View Related

Android :: Database That Only Is Reachable Through ContentResolver

Nov 12, 2009

for some reason i would be executing a raw query or at least a query with group by clause and having clause to the table calls from database contacts.db.Adding the group by clause and the having clause to the where clause will result in exception.Open the database(/data/ data/ com.android.providers.contacts/databases/contacts.db) with SQLiteDatabase. open Database()also throws an exeception.

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

Android :: How To I Make A New Cursor From First Two?

Jun 25, 2009

I have two tables I want to (inner) join, Contacts.People and Contacts.ContactMethods. The result will be displayed in a ListActivity. After looking into this, it appears that I should use CursorJoiner. So the code would look something like this: So my question is, how to I make a new cursor from the first two?

View 2 Replies View Related

Android :: SQL Cursor And GROUP BY?

Nov 19, 2010

I have a query that is making use of GROUP BY so that the results are grouped by a date column. My question is this:

When I move through the cursor to get the results of the query, how can I get the multiple items associated with each group into my vector? For example, I want to get BOTH "Item X" and "Item Y" for October 16, 2010. Currently, I get them each separately.

Here is my code:

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

So, when I get the results from my Vector, I will get:

October 12, 2010
- Item X

October 12, 2010
- Item Y

And I want:

October 12, 2010 - Item X, Item Y

Yes, I do have to change my Vector to support multiple items, but hopefully you get what issue I'm facing...

View 1 Replies View Related

Android :: Cursor - Get The Field Value

May 24, 2009

I have problems with Cursor in my Android application.

I have a SQLiteDatabase that return me Cursor when I try to fetch the values with :

code:.......

But I don't know how to obtain the value of the field in the Cursor.

If I do that :

code:........

I obtain the name of the columns (_id, title, body) but not the value.

View 2 Replies View Related

Android :: How To Return Typeface From Cursor?

Oct 30, 2009

I want to make a content provider for font file. But I can not find any way to return a Typeface from Cursor. According to SDK reference, Matrix Cursor sounds like a solution, but it doesn't support any object except String,Long,Double,Short,Flow.

View 4 Replies View Related

Android :: Simplecursoradapter - Close Cursor

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

Android :: AVD Cursor - Windows Default

Nov 10, 2010

When i use the AVD to test my apps the cursor in the avd window changes from the windows default cursor to a custom black cursor. I would like to use the windows default.

View 5 Replies View Related

Android :: Customised Sorting On Cursor

Sep 7, 2009

I want to do customised sorting on cursor which is returned after query is done. Is it possible to do? Is there any way to do updates on Cursor?

View 7 Replies View Related

Android :: Sharing Cursor Between Activities

Nov 21, 2010

I think the following scenario is common, but I can't figure the way to implement it:

We have three Activities, and one database. We ask the user for an input to search in the database. The query should get none, one or may results.

If you get none you simple inform the user.
If you get only one, you show it in a new activity with the right view.
If you get many you show them in a list to let the user to chose the right one and then you pass that to the activity which with show the data in the case of one result only.

The problem is that, in order to know the number of results, you need to do the query (and get the cursor) in the first activity. And in the case you get more than one result you need to send the data (pass the cursor?)to the list acitivty. Doing the query again in the list activity can't be right, right?

I'm aware that you can share cursors by using a content provider, but as the activities are from the same application and the data is private (useless outside), don't see the point of making it avaliable to anyone else.

I read here around that you can crate a parcelable cursor and send it in bundle, but I'm not sure if that is the right use.

View 1 Replies View Related

Android :: An App To Display Cursor Position

May 29, 2009

I am new in Android application programming.I need to develop an android application which simply displays the cursor position (co ordinates) very urgently.If any has some pointers in same would be a great help to me.

View 4 Replies View Related

Android :: Cursor Position At The End Of Text

Aug 26, 2009

When i try to edit and already stored notepad ,i see the cursor at the end of first line.I want to make it appear to the end of the text.Please help me in this.

View 2 Replies View Related

Android :: How To Input Cursor Position On Tap?

Feb 18, 2010

I want to read my cursor position so that, after a tap, I can convert the screen x,y coordinates to a Geopoint for distance calculations.I found a snippet to convert x,y coordinates to a Geopoint and probably could use Projection instead, but how do I input those screen x,y values in the first place? This is probably straightforward, but I'm confused.The class Cursor seems to be something different than what I need

View 2 Replies View Related

Android :: EditText's Cursor Position

Aug 10, 2010

User wrote some text in EditText, then touched it somewhere in its field. Cursor position changed.I need to determine changed cursor position, and do some code. How can I do this?

View 1 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







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