android - Loading data from network per item in RecyclerView -
from server (api rest), can obtain list of item (products) info of each one. map list in recyclerview adapter. show loading view until receive list.
however, have show more info per item in each row, can info http request (per item), sending id of product. therefore, want fill ui of each row info asynchronously (when row showing).
how better way of achieve that? think same problematic asynchronous image loading, should libraries such picasso or universal image loading. isn't it?
do know library in order me that?
thanks in advance!
you achieve using rxjava library. example, in onbindviewholder method possibly this:
observable.fromcallable { loaddataasync(position, <other arguments need>) }.subscribeon(schedulers.io()) .observeon(androidschedulers.mainthread()) .subscribe { loadeddata -> holder.setadditionaldata(loadeddata) } of course must keep track on each subscription , unsubscribe after item has been recycled in order prevent memory leaks.
anyway should revise api design , make server send data in 1 request/response cycle rather making tons of small http requests each item. in case problem disappears.
Comments
Post a Comment