android-cursor

How to use Cursor Loader to access retrieved data?

放肆的年华 提交于 2019-12-07 14:18:25
问题 I'm a little confused about how to use the cursor to access the data that I need using the CursorLoader model. I was able to use a SimpleCursorAdapter and pass the cursor to the swapCursor method of the adapter within the onLoadFinished method that you have to implement as follows. @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { facilityAdapter.swapCursor(cursor); } Now I need to query the database and based on the number of rows returned display an integer. How

When should I close a cursor and db?

情到浓时终转凉″ 提交于 2019-12-07 10:01:09
问题 I use the same cursor multiple times in the custom view in its different methods. Should I close the cursor after each use or can I keep it open until the view is destroyed? And the same for the database, can it be opened once the activity that holds this view is created and closed when the activity is destroyed? I continuously receive an error 'close() was never explicitly called on database...' when I do as described above. 回答1: Should I close the cursor after each use or can I keep it open

IllegalStateException: couldn't move cursor to position x

末鹿安然 提交于 2019-12-07 07:31:06
问题 I have a custom CursorWrapper to provide a filtered ListView. My filter goes through each element finding the last version of each 'key' and displaying that into the instantiateTemplateAdapater() . When I delete an item (I select it and then call DeleteFormsTask.execute which will run an AsyncTask and delete the entry. When I attempt to delete a file, it returns the error couldn't move cursor to position x where x is the position of the item deleted. There is no line errors and I have pasted

Android MVP: safe use Context in Presenter

旧城冷巷雨未停 提交于 2019-12-06 17:55:02
问题 In my app I work with ContentProvider and use LoaderManager.LoaderCallbacks<Cursor>. Fragment (View) public class ArticleCatalogFragment extends BaseFragment implements ArticleCatalogPresenter.View, LoaderManager.LoaderCallbacks<Cursor> { @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return onCreateArticleCatalogLoader(args); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { data.registerContentObserver(new LoaderContentObserver(new Handler()

how to select unique contacts from android

a 夏天 提交于 2019-12-06 00:54:21
问题 i want to select unique contacts from android only that contacts which have phone numbers. i am using this code ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.Contacts.DISPLAY_NAME); // Find the ListView resource. mainListView = (ListView) findViewById(R.id.mainListView); // When item is tapped, toggle checked properties of CheckBox and // Planet. mainListView .setOnItemClickListener(new AdapterView

How to use Cursor Loader to access retrieved data?

*爱你&永不变心* 提交于 2019-12-05 19:47:45
I'm a little confused about how to use the cursor to access the data that I need using the CursorLoader model. I was able to use a SimpleCursorAdapter and pass the cursor to the swapCursor method of the adapter within the onLoadFinished method that you have to implement as follows. @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { facilityAdapter.swapCursor(cursor); } Now I need to query the database and based on the number of rows returned display an integer. How do I access this information? There is some information that I would like to store (the _id) of certain

When should I close a cursor and db?

爷,独闯天下 提交于 2019-12-05 17:30:40
I use the same cursor multiple times in the custom view in its different methods. Should I close the cursor after each use or can I keep it open until the view is destroyed? And the same for the database, can it be opened once the activity that holds this view is created and closed when the activity is destroyed? I continuously receive an error 'close() was never explicitly called on database...' when I do as described above. Should I close the cursor after each use or can I keep it open until the view is destroyed? Depends. If the cursor result is not going to change meanwhile (e.g. remote

IllegalStateException: couldn't move cursor to position x

空扰寡人 提交于 2019-12-05 16:14:40
I have a custom CursorWrapper to provide a filtered ListView. My filter goes through each element finding the last version of each 'key' and displaying that into the instantiateTemplateAdapater() . When I delete an item (I select it and then call DeleteFormsTask.execute which will run an AsyncTask and delete the entry. When I attempt to delete a file, it returns the error couldn't move cursor to position x where x is the position of the item deleted. There is no line errors and I have pasted my entire error log for it below as well. When I change new SmartCursorAdapter(c) in

IllegalStateException: database already closed (using ViewPager)

巧了我就是萌 提交于 2019-12-05 11:06:20
I'm stumped as to what is causing this error, as I have made sure that I am closing my database adapter properly (at least I think I am). Here's what LogCat's saying (the tag for all of them is AndroidRuntime): FATAL EXCEPTION: main java.lang.IllegalStateException: database /data/data/com.acedit.assignamo/databases/data.db (conn# 0) already closed at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2082) at android.database.sqlite.SQLiteDatabase.lock(SQLiteDatabase.java:413) at android.database.sqlite.SQLiteDatabase.lock(SQLiteDatabase.java:400) at android.database

Intent.ACTION_PICK returns empty cursor for some contacts

倖福魔咒の 提交于 2019-12-04 23:52:52
I have an app in which one aspect is for a user to select a contact and send a text to that contact thru the app. The app only works with some contacts and fails on others. More precisely: for the contacts that I entered into my contact book by hand, the Intent.ACTION_PICK has no trouble finding and returning them to the app, i.e. cursor.moveToFirst() is true. But for the contact that were imported by Facebook (my phone is set to sync with Facebook contacts), I get the following android.database.CursorIndexOutOfBoundsException after I click on the contact. One glaring question I have is: why