I have a database in a server and from a Tablet I take some values from one table in the database. I load this information correctly into a list but I would like to know why
The update function should be called from UI thread. My answer is actually similar to @user1621629's answer with that difference that I am using rxJava, so here's working code that solve this problem for me:
this.subscriber = myAdapter.getSubscriber(); // keep for unsubscribe in destroy
dataSource.subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(this.subscriber);
So I set all execution in order to get data for the list to computation thread, but showing result in UI thread.
Here's how I create subscriber for this:
public class MyListAdapter extends RecyclerView.Adapter {
private List mDataset = new ArrayList<>();
public Subscriber getSubscriber() {
return Subscribers.create(new Action1() {
@Override
public void call(ListItem[] listItems) {
mDataset.clear();
mDataset.addAll(Arrays.asList(listItems));
notifyDataSetChanged();
}
});
}
......