How could i manually update the recyclerview of my app? - android

I am new to Android development. I intended on users to submit their information via Google Docs until I created a website for my app. I currently have a recyclerview to display posts. These posts consist of imageviews and textviews. My question is what is the most efficient way I could update my recylerview to display their submitted information if approved. If not plausible what would you suggest to manage the content in my program? Also keep in my mind I plan on developing the same application in Ios in the future and would like for each app to display the same information.

You could represent the data fetched from your web service in an SQLite Database (a good tutorial on how to create/access sqlite databases in android can be found here:
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/).
Then you could use a CursorLoader and a CursorAdapter for the RecyclerView and swap the cursor when the loader finishes.
If you are modifying your dataset simply call onContentChanged() and your loader will requery and publish the results automatically.
Here you'll find a decent CursorAdapter implementation for RecyclerView: https://gist.github.com/skyfishjy/443b7448f59be978bc59
And here is a good documentation on how to use the CursorLoader with the LoaderCallbacks: https://developer.android.com/training/load-data-background/setup-loader.html

Related

Show search results on RecyclerView using CursorAdapter,CursorLoader

I have a RecyclerView which loads data from the database using CursorLoader, CursorAdapter, ContentProvider and all that stuff. It is properly showing the data. But what I want is a search functionality where user types and the RecyclerView's data changes accordingly. I have done it before but with CursorLoader I'm not able to do.
I'm thinking of firing another Loader with different Id? Is it a good idea?
Here's the GitHub link of my project.

Instagram like app Realm vs CursorLoader

I have an instagram like app in which I receive data from a server(imageUrl, username, about) and I store it in a cursorLoader and after that I take the data from the cursorLoader and put it in a RecyclerAdapter. The images are being loaded using the Volley library.
I recently found out about the realm library. Should I use this instead of the cursorLoader ? I'm not even sure why I needed the cursor loader, but I implemented it and it's working. I think I only need to store the user once connected so it doesn't have to connect every time the app is called if he did not disconnect. Which would be the best approach to make this app work smoothly.
Which is the best way to keep some data displaying like the instagram/facebook feed once it was downloaded (even after the user killed the app and turned it on again). Could you give me any tips ?
If you want to store data after they have been downloaded and have it persisted between app restarts, then a database is a good choice. Whether you want to use normal Cursors, some ORM or Realm is really up to what you value and what trade-offs you are willing to accept.
That said, the primary reason for a CursorLoader is to
Load a lot of data asynchronously.
Hook into change notifications from a ContentProvider
If you don't use a ContentProvider, a CursorLoader looses a lot of its power.
The same functionality a CursorLoader provides (automatic refresh on changes/handle lots of data) can be expressed with far less code using Realm:
RealmResults<ServerData> results = realm.where(ServerData.class).findAllAsync();
RealmBaseAdapter adapter = new RealmBaseAdapter(context, results, true);
listView.setAdapter(adapter);

Implementing a ContentProvider just to be able to use Loaders

I have an sqlite db with data I want to load async to a ListView.
I know that Loaders enable easy async data fetching + getting notified on data changed, but from what I see, Loaders work with ContentProviders.
Since in the documentation, it says that
A content provider is only required if you need to share data between multiple applications
I find it weird that using Loaders require a ContentProvider.
I found this thread where it says in one of the answer's comments that
... taking this I just feel I should implement a content provider even so it seems like a overkill for any small database i might want to list on the display ...
Is this the recommended course on action? Is there an alternative?
CursorLoader is designed to work with a content provider, but you can implement your custom Loader to work directly with the database, without implementing a content provider.
take a look -->
Android Custom Loader to Load Data Directly from SQLite Database

What is the best approach for asynchronously loading data from SQLite into an Android ListView?

I'm new to Android and have successfully implemented an ArrayAdapter to display a list of simple objects in a ListView. I have also created a class that extends SQLiteOpenHelper and I'd like to use this to display a list of rows from the database in the ListView.
From what I can tell, it seems like I should be using a Loader to asynchronously query the data, and act as a middle man between my data and the UI.
The Loader and CursorLoader documentation only refers to how to achieve this when querying a ContentProvider. This led me to think that the best approach may be to create a ContentProvider which provides a structured interface to my database - but the Android documentation on creating a ContentProvider states:
You don't need a provider to use an SQLite database if the use is
entirely within your own application.
Are there any particular reasons why I shouldn't write a ContentProvider? Unless I'm missing something it seems like this would provide a good abstraction for the data layer and mean I can have all the benefits of using a CursorLoader when consuming it.
In my case the database is only for use by my application - so what alternatives are there and are there any good tutorials which show the process start to finish?
Thanks!

Android db loading chat for chat application

I'm creating a chat application and I need a little bit of guidance. I am using a sqlite database to store the chat as it comes in. I want my Activity, when it's open, to load the chat history from that particular chat and to continue to refresh as new chat is entered (my main question is how do I go about doing this).
Should I use a CursorAdapter with an inital cursor of a query containing the chat for that conversation and set it as the adapter for the ListView? I have tried this, but the data doesn't refresh when I insert into the database.
I know I didn't provide any code, but general conversation about what the best way is to go about this is welcome. Thanks!
Let me also mention that I need this to work for android 2.3.3 (API 10) and up (CursorLoader and all that is not available until API 11 which I did read a little about). The other thing I can do is use an ArrayAdapter and add chats directly into that (if the activity is open) and also insert it into the db in case it is not and then on onResume(), clear the ArrayAdapter and query all the convo once and readd each. Would this be the most optimal way?
Have a look at LoaderManager. Really simple and does exactly what you want.
It is available for 2.3.3 using the compatibility library.
http://developer.android.com/reference/android/app/LoaderManager.html

Categories

Resources