android-cursor

Android ListView: how to avoid database query in bindView()? Need to fetch one to many relationship data

梦想的初衷 提交于 2019-12-11 02:56:45
问题 I have a list view to display albums. In each album list item, I need to display some information from each photo in this album. Here is how my cursor loader looks like: @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(this, AlbumsColumns.CONTENT_URI, null, null, null, null); } @Override public void bindView(View view, Context context, Cursor cursor) { long albumId = cursor.getLong(cursor.getColumnIndex(AlbumsColumns._ID)); Cursor photoCursor =

Error: Attempted to access a cursor after it has been closed?

*爱你&永不变心* 提交于 2019-12-11 02:19:51
问题 In my application I'm fetching inbox messages from native application to my application . Also there are checkboxes to select multiple messages.But the problem arises are no messages are displaying in listview while running code and also showing error android.database.StaleDataException: Attempted to access a cursor after it has been closed. ArrayAdapter<SMSListModel> adapter; List<SMSListModel> list = new ArrayList<SMSListModel>(); TextView textViewSMSSender, textViewSMSBody public void

Filter out items from cursor

…衆ロ難τιáo~ 提交于 2019-12-11 02:15:35
问题 I'm trying to remove an item from a cursor object, and I'm not sure how to do it (or if it's possible). I don't actually want to remove the item from the database, just 'filter' it and not display it, depending on user settings. For example here, FILTER_TEXT is from the application preferences and it contains text that the cursor must contain or else it is removed. Cursor mCursor = mDB.query(dbTable, new String[] {KEY_ROWID, KEY_NAME, KEY_URL}, null, null, null, null, null); if (mCursor

How to delete contacts from sim in android

爷,独闯天下 提交于 2019-12-11 01:41:02
问题 I did following code for deleting selected contacts from sim card. but its not deleting and also not throwing any error. protected void DeleteContacts(ArrayList<String> ids){ int flg = 0; String[] strids = new String[ids.size()]; strids = ids.toArray(strids); for (int i = 0; i < strids.length; i++) { Cursor sims = getActivity().getContentResolver().query( Uri.parse("content://icc/adn"), null, "_id=?", new String[]{strids[i]}, null); sims.moveToFirst(); if (sims.getCount()>0) { String

MediaStore.Images.Thumbnails.getThumbnail returns wrong thumbnail instead of NULL

拜拜、爱过 提交于 2019-12-09 14:40:54
问题 Consider the scenario as in this picture: Three photos, one of them is a large GIF file (3MP). I'm querying MediaStore in order to retrieve the correspondent thumbnails. If I initialize the Cursor via CursorLoader with this sortOrder: MediaStore.Images.Media.DATE_ADDED + " DESC"" What happens: MediaStore returns the previous successfully retrieved thumbnail: Expected behaviour: when MediaStore cannot retrieve the thumbnail of a given image for some reason it has to return NULL, as per its

How to create Cursor data without getting data from the DataBase in Android application?

痞子三分冷 提交于 2019-12-08 15:38:22
问题 In my Android application, I am using Sqlite DataBase to store the data from the server. I am using ContentProvider and ContentResolver to access the data from the DataBase and using CursorAdapter to bind the data to the ListView. As soon the data is inserted into the DataBase, CursorAdapter will be notified to update the ListView. Also, whenever I scroll the ListView, I get new data from the DataBase table and ListView will be updated. But once I reaches to the end of the table row, I need

How to fill a Spinner with a Cursor after API level 11?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 06:15:25
问题 I have found lots of answers on SO and other websites about how to fill a Spinner with a Cursor , but all of them use the deprectated SimpleCursorAdapter(Context, int, String[], int[]) constructor to do that. No one seems to describe how to do it with API level 11 and above. The API tells me to use the LoaderManager , but I'm not sure about how to use that. 回答1: I would suggest implementing your own CursorAdapter instead of using SimpleCursorAdapter. Implementing a CursorAdapter is no harder

Is it safe to pass a cursor to another activity?

巧了我就是萌 提交于 2019-12-08 01:47:03
问题 I'm trying to do horizontal swiping using a cursor but I'm just not grokking something, and hopefully someone here can help me understand. I've got an activity that shows a list of items. It uses a ListView that is backed by a custom CursorAdapter , and that adapter is managed by a LoaderCallback . This is all standard stuff. When the user clicks an item in the list, I want to show detailed information about that item. Currently I start a new activity, passing the ID of the selected item.

Cursor not binding text correctly with custom adapter

一个人想着一个人 提交于 2019-12-07 21:37:30
问题 My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items in my database correctly. it does not display the text in the TextView, what else do I have to do to the cursor for it to show the correct text? I thought I had to override the bindView but that had no effect Setting the adapter: public void populateList(){ String[] fields = new String[] {BowlersDB.NAME}; Cursor c = getActivity().getContentResolver().query(BowlersDB.CONTENT_URI, new String[]

update contact name & number in android programmatically

时光毁灭记忆、已成空白 提交于 2019-12-07 16:26:39
问题 I create an Application to Read, Update, Delete Contacts Details. Here is a problem to updating Contact name and number.Could anyone help me please how can I do that. I am using the following code, but it's not working. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_fragment_edit, container, false); textView = (TextView) view.findViewById(R.id.tvnew1); imageView = (ImageView)