android-cursorloader

SQLite data to a RecyclerView

天涯浪子 提交于 2019-12-04 02:46:38
The app has data in a SQLite database. The UI is primarily a RecyclerView. The question is how to best to transfer data from the database into the UI, whilst keeping off the main thread? I originally planned to use a CursorLoader, ContentProvider, and RecyclerView. But reading around it looks like RecyclerView has no out-of-the-box support for Cursor-supplied data. Dang. That then leaves me with a few other options... AsyncTask to load the data, put it into model objects, and pass into the RecyclerView Adapter. Aside from being ugly, it isn't config-change friendly. A custom Loader that loads

GROUP BY with CursorLoader

耗尽温柔 提交于 2019-12-04 02:31:06
How do I define a GROUP BY query for my CursorLoader? The two constructors for a CursorLoader I see take either a single Context or a Context , Uri , projection , selection , selectionArgs and sortOrder . But no groupBy . (I'm using the support package for a Android 2.3 device) Not really... You can define a specific URI to your specific GROUP BY clause. For example, if you have a table mPersonTable, possibly grouped by gender, you can define the following URIs: PERSON PERSON/# PERSON/GENDER When querying, switch between your queries so you can add your group by parameter: public Cursor query

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

社会主义新天地 提交于 2019-12-04 02:08:50
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 Javadoc: "... Returns A Bitmap instance. It could be null if the original image associated with origId

ListView filtering with CursorLoader AND FilterQueryProvider?

我与影子孤独终老i 提交于 2019-12-03 16:44:40
In our Project we deal a lot with Lists and used it in the past with the following "pattern": ListView is in a Fragment, gets initialized in onActivityCreated where we first start CursorLoaders and then in onFinish swapCusor to the ListAdapter. We then implemented a search functionality using the filterQueryProvider which just returns a cursor with contentResolver.query(...). If i have done some orientation changes while something in the list was selected i got the following error in many cases (not regularly): android.database.StaleDataException: Attempted to access a cursor after it has been

Fetch Genre name list which have songs in it

主宰稳场 提交于 2019-12-03 15:41:29
I am fetching Genre list from media content Provider of android using CursorLoder class. below is my cursor query to fetch the list of Genre. public Loader<Cursor> onCreateLoader(int id, Bundle args) { // currently filtering. Uri baseUri; baseUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI; String[] STAR = { "*" }; return new CursorLoader(getActivity(), baseUri, STAR, null, null, null ); } Now, i got all the genre list from the media content provider but the problem with the data i got. I also got the genre name which is created before but right now i don't have song in it. I only want the

Using CursorLoader to get emails causes duplication of emails

我只是一个虾纸丫 提交于 2019-12-03 11:58:54
I am trying to get email ids of uses contacts. For that I am using Cursor Loader. There is one problem I am getting duplicate email ids also. How to remove email duplicacy. Should I use raw query "SELECT DISTINCT" instead of using CursorLoader or there is some other solution? @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA}; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; String

CursorLoader for Multiple ContentProviders

孤街浪徒 提交于 2019-12-03 11:39:15
I need to make a ListAdapter that presents data from multiple ContentProviders. The ContentProviders themselves represent one table each from relational database. I want to use the CursorLoader system to retrieve aggregate data into ListView. Is this possible to do with 1 loader or do I need to use multiple loaders? I'd prefer to use one. I'm not sure how I can have 2 ContentProviders interact with each other beyond doing the join manually in code which doesn't seem like a great option either. rOrlig You will have to write a Custom Loader class. For example: public class FooLoader extends

Showing specified page when view pager is first created

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 09:07:15
I have a fragment that contains a ViewPager . This ViewPager is backed by a PagerAdapter that uses a Cursor . The cursor is managed by LoaderCallbacks . I'm using the v4 support libraries here. What I want is to create the fragment and have the view pager showing a specified page, rather than starting at page 0. I know that ViewPager has a setCurrentItem() method, but the data may not yet be loaded when the ViewPager is created. What I need is to listen to the adapter for data set changes, and if that is the first such change, then call setCurrentItem() on ViewPager . However the PagerAdapter

Testing ViewPager (and CursorLoader) with Robolectric

谁说胖子不能爱 提交于 2019-12-03 03:23:18
问题 Does anyone know how to test the following setup using Robolectric? Fragment containing a ViewPager, data loaded with a CursorLoader. With the code below, the CursorLoader is never pushed into the adapter for the view pager. I get stuck at the await() call. EventsFragmentTest.java: @RunWith(CustomRobolectricTestRunner.class) public class EventsFragmentTest extends AbstractDbAndUiDriver { // which element in the view pager we are testing private static final int TEST_INDEX = 0; protected

Testing ViewPager (and CursorLoader) with Robolectric

爷,独闯天下 提交于 2019-12-02 16:54:29
Does anyone know how to test the following setup using Robolectric? Fragment containing a ViewPager, data loaded with a CursorLoader. With the code below, the CursorLoader is never pushed into the adapter for the view pager. I get stuck at the await() call. EventsFragmentTest.java: @RunWith(CustomRobolectricTestRunner.class) public class EventsFragmentTest extends AbstractDbAndUiDriver { // which element in the view pager we are testing private static final int TEST_INDEX = 0; protected SherlockFragmentActivity mActivity; protected EventsFragment_ mFragment; @Override @Before public void setUp