How to edit LiveData<PageList> before setting to adapter - android

I use this
link
to make a pagedList from Room. But i must fetch other data from another remote before set adapter
How can i edit LiveData> results before set data?

Related

Is there any way to observe specific actions on database using Room?

This docs provide a way to observe data stored in database. But this is too generic. This emits a new value whenever any changes occur to that table. Using this to update recyclerView means, on every update I have to replace old dataset by new one and call notifyDatasetChanged on the adapter. But instead is there any to specifically get updates like onRowInserted, onRowUpdated and onRowDeleted which returns only the data in the row being modified, as this helps me in making specific notifyItemInserted, notifyItemChanged and notifyItemRemoved calls to the adapter.

update the list view when data changes

I am creating Android application for an IOT product .
I am uploading sensor data to an web serves developed in REST architecture.
web service is working perfectly .
I want show in real time that if sensor data changes.
I want retrive data and update the Textview
how can I do that?
For refreshing listview data,you need to use the following line of code,
adapter.notifyDataSetChanged();
where,
adapter = your listview adapter object
Write above line of code after you retrieve data from a server or local database.
You want to update a textview or a listview?
If it is that you want to keep adding new records to a list view, just add the items to the listview adapter as they come in and call youradapter.notifyDataSetChanged() so the listview updates its content.
Add this Code in your adapter list like :
Adapter_Constructer(List<String> data){
this.data=data;
notifyDataSetChanged();}
and then update it when u want
or just use :
adapter.notifyDataSetChanged();
in your response method.
or Reinitialize and reset adapter then call adapter.notifyDataSetChanged();

Kotlin clear an adapter

What is the best way to clear an adapter in Kotlin?
I was trying to clear a recyclerview and update the values.
I am using LoaderManager and I am kind of stuck in this state.
If you want update recyclerview after adding/removing data in your adapter use this code
If you use Arraylist to store the data objects then just clear your list and call notifyDataSetChanged.
dataList.clear()
recyclerView?.adapter?.notifyDataSetChanged()

RecyclerView and Adapter, which one should take care of Data Change?

In RecyclerViewFragment Class, there is MovieData, and the Adapter Class stores MovieData.getMovieList( ).
My question is, when Event Handler be triggered,
Add / Delete data directly in RecyclerViewFragment Class
Define add( ) / delete( ) function in Adapter Class and call adapter.add( ) / adapter.delete( ) in RecyclerViewFragment Class
Which way is the better design? Who has the responsibility to take care of data change?
I would suggest to have RecyclerViewFragment containing the data. And create an adapter passing the reference to the data. For example:
mAdapter = new CustomAdapter(mMovieData.getMovieList());
Then in the RecyclerViewFragment just perform the needed actions such as add / remove such as:
mMovieData.getMovieList().add(index);
Think this is the most common way todo it. You do not want to replicate the getMovieList data twice in adapter and RecyclerViewFragment. This will get confusing.
If data change is happening after adapter has been initialized, then it should be handled inside adapter. Adapter also has a nifty function notifyDataSetChanged() which will update item positions inside the adapter when data has changed.
The recyclerview is not concerned with the data, this is all handled by the adapter you have created to present the data. Have a look at the functions here to see what options you have in regard to data changes.
Adapter is the responsible class for filling a list with data ,for example if you have a list that need to be filled with data lets say SCORES then the adapter is the one responsible for filling these scores in the list. on the other side, RecyclerView is reposnsilbe for making the adapter fill it with more speed and effecieny, the recyclerView uses views that are previously used to display data by the adapter and place them in cache for later reuse to display the same type object so that it doesn't have to initialize a new object each time the adapter want to fill item in the list which make it faster.
and here is a link that might help you as well :
Hope my answer have helped you.

How to update CustomListView item in Android using Model where the model data is downloaded from internet?

I have a CustomListView in my android app. Each item consists of two pieces of text which are to be retrieved from an online SQL database. I'm using a Model class called ListModel and a custom adapter called CustomAdapter. I'm using an Asynctask to download the model data from the internet. But the problem is that, adding of a ListModel object to my ArrayList is not working when I do it in the onPostExecute method of my Asynctask. So, the listview is not getting updated. How do I display the Model items on my Custom List as soon as they get downloaded? Is there any way to do that?
This type of problems occures when adapter not properly notify after data downloaded. Notify your adapter in postExecute by notifyDataSetChanged () method
Generally this is because notifyDataSetChanged() isn't called on the arrayadapter. (but stacktraces/your code would be helpful)
In addition, this is a prime use of an in-memory SQLite database (if you plan on doing any custom queries)
Or a full on-disk SQLite DB if you want to cache data.
(Adding a content provider(by just surrounding the SqliteDB) would also be nice if you want to abstract away some more and provide observers, etc. )

Categories

Resources