android-cursor

How can I create a list Array with the cursor data in Android

Deadly 提交于 2019-11-27 17:31:33
How can I create a list Array (the list display First Alphabet when scroll) with the cursor data? Isaac Waller Go through every element in the Cursor , and add them one by one to the ArrayList . ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>(); for(mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) { // The Cursor is now set to the right position mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT)); } (replace WhateverTypeYouWant with whatever type you want to make a ArrayList of, and WHATEVER_COLUMN_INDEX_YOU_WANT

How to update existing contact?

夙愿已清 提交于 2019-11-27 14:35:38
问题 I have one existing contact, I need to add a work address to that existing contact. I am using the following code, but it's not working. String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'" + " AND " + ContactsContract.CommonDataKinds.StructuredPostal.TYPE + "=?"; String[] phoneArgs = new String[] {String.valueOf(ContactId), String.valueOf( ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

大兔子大兔子 提交于 2019-11-27 10:29:53
Would it be OK to have a single instance of SQLiteOpenHelper as a member of a subclassed Application, and have all Activities that need an instance of SQLiteDatabase get it from the one helper? Having a single SQLiteOpenHelper instance can help in threading cases. Since all threads would share the common SQLiteDatabase , synchronization of operations is provided. However, I wouldn't make a subclass of Application . Just have a static data member that is your SQLiteOpenHelper . Both approaches give you something accessible from anywhere. However, there is only one subclass of Application ,

Using CursorLoader with LoaderManager to retrieve images from android apps

风流意气都作罢 提交于 2019-11-27 08:18:28
问题 At the moment I’m using getContentResolver().query()/managedQuery() to get a cursor to retrieve images from the gallery app. Because the APIs I’m using are partly deprecated I wanted to use CursorLoader with LoaderManager. /** * Creates a cursor to access the content defined by the image uri for API * version 11 and newer. * * @return The created cursor. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private Cursor createCursorHoneycomb() { String[] projection = { MediaStore.Images.Media.DATA }

Cursor.getType() for API Level <11

那年仲夏 提交于 2019-11-27 03:05:19
问题 I'm querying the CallLog content provider and need to detect the column types. In Honeycomb and newer (API Level 11+) you can get a columns preferred data type by calling the method Cursor.getType(int columnIndex) which returns one of the following types: FIELD_TYPE_NULL (0) FIELD_TYPE_INTEGER (1) FIELD_TYPE_FLOAT (2) FIELD_TYPE_STRING (3) FIELD_TYPE_BLOB (4) How can I accomplish this on pre-Honeycomb <11 devices? I've tried the following: for ( int i = 0; i < cursor.getColumnCount(); i++ ) {

Using String[] selectionArgs in SQLiteDatabase.query()

馋奶兔 提交于 2019-11-27 00:51:00
问题 How do I use the String[] selectionArgs in SQLiteDatabase.query() ? I wish I could just set it to null , as I have no use for it. I am just trying to load an entire unsorted table from a database into a Cursor . Any suggestions on how to achieve this? 回答1: selectionArgs replace any question marks in the selection string. for example: String[] args = { "first string", "second@string.com" }; Cursor cursor = db.query("TABLE_NAME", null, "name=? AND email=?", args, null); as for your question -

android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow

廉价感情. 提交于 2019-11-26 20:40:27
I am developing an application which download some files and save their text in file_content field to database. The file sizes can vary from some KBs to 10 MB. The app works for all sizes while saving. The problem occurs when using select statement on long file_content records. It gives java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow when fetching such rows. Are there any limits on field content size? If so, then why it is letting us to save and giving error while retrieving? Here is my code snipped that fetches row: public String getFileContent(MyFile gc) { if(

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

泄露秘密 提交于 2019-11-26 11:55:43
问题 Would it be OK to have a single instance of SQLiteOpenHelper as a member of a subclassed Application, and have all Activities that need an instance of SQLiteDatabase get it from the one helper? 回答1: Having a single SQLiteOpenHelper instance can help in threading cases. Since all threads would share the common SQLiteDatabase , synchronization of operations is provided. However, I wouldn't make a subclass of Application . Just have a static data member that is your SQLiteOpenHelper . Both