Andrew
Andrew

Reputation: 2157

How can I update item of recyclerview from dialogfragment?

In my app I get some data from server in json. Then I fetch fields from json and fill my RecyclerView list with custom adapter. This list is filled with data about jobs. When I click on a job of my recyclerView I move from hosting fragment to dialogfragment for viewing it. This dialogFragment contains homesUp button after pressing which I return to hosting activity. At this dialogFragment I have button which send request to server about this job for adding it to another DB at server. But when I press this button and send request to the server then after returning to hosting activity I see that data of selected isn't changed. I have several ways of solving this problem:

  1. Add to my Singleton class variable of ArrayList which will be filled by data of shown job and then I will check whether my Arraylist from Singleton contains this id
  2. another method - notifyItemChanged()

All these methods don't work because my list is filled by old data and I only dismiss dialogFragment and return to fragment which contains the list with old data.

Only one way - send request to server for filling the list again.

So, I need your help or useful advice :)

Upvotes: 0

Views: 217

Answers (1)

Abhijeet Kumar
Abhijeet Kumar

Reputation: 351

You need to broadcast changed data from dialog fragment to previous screen. For doing this can use LocalBroadcastManager or rxjava or even live data.

Or create a pagedlistadapter from paging library released in android architecture complement and load data directly from query. Reference: https://developer.android.com/topic/libraries/architecture/paging

Upvotes: 1

Related Questions