0

In my app, I'm trying to implement a network search on type. I've a fragment with a search text and tabLayout with 3 tabs (fragments) all fragments are using the same viewModel and same call (with different params) to fetch data from the network.

I followed the these examples: https://blog.mindorks.com/implement-search-using-rxjava-operators-c8882b64fe1d

https://proandroiddev.com/implementing-search-on-type-in-android-with-rxjava-9ece00f4e266

On the first example, it says that using switchMap I can avoid the network call results which are not needed more but on the second example they make the call on the subscribe.

Which method will be better? If the first one, I would love to get an example how can I implement it (I'm using PageKeyedDataSource to get the data in pages)

Thanks.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sharas
  • 1,985
  • 3
  • 20
  • 43
  • The second link you provided is kind of broken now so I can't check but making network call is not a good practice. `switchMap` is a good start. – Sanlok Lee Jul 12 '19 at 00:13
  • Thanks, actually, i need to do the same as described here: https://stackoverflow.com/questions/39558885/how-to-implement-search-feature-with-searchview-retrofit-and-rxjava-rxbindings but I'm not sure how can I do it using ViewModel and LiveData – Sharas Jul 13 '19 at 16:54
  • `LiveData` does have `switchMap` but it is difficult to implement advanced features like `throttle` or `debounce` with `LiveData`. See if some of these answers [here](https://stackoverflow.com/questions/51154786/android-implement-search-with-view-model-and-live-data) helps you, and if those answers are not enough you can ask another question about that specific part that you need more help with. – Sanlok Lee Jul 13 '19 at 23:54

0 Answers0