Support RecyclerView doesn't show anything until touched

前端 未结 9 1803
后悔当初
后悔当初 2021-02-04 23:41

I\'m using the support RecyclerView in my app, and I see the most bizarre thing. It doesn\'t display any items until I touch to scroll. Then, all of a sudden, the RecyclerView p

9条回答
  •  被撕碎了的回忆
    2021-02-05 00:26

    If anyone else is having this issue using RxJava and Retrofit, I solved this issue by adding the .observeOn(AndroidSchedulers.mainThread()) operator into my method chain before subscribing. I had read this was taken care of by default, and thus not explicitly necessary, but I guess not. Hope this helps.

    Example:

    public void loadPhotos() {
        mTestPhotoService.mServiceAPI.getPhotos()
                                     .subscribeOn(Schedulers.io())
                                     .observeOn(AndroidSchedulers.mainThread())
                                     .subscribe(photoList -> mRecyclerActivity.OnPhotosLoaded(photoList));
    }
    

提交回复
热议问题