android - 图像未使用 Rx Observable 和 Retrofit2 加载 Picasso

标签 android android-recyclerview picasso observable retrofit2

我正在学习 RxJava (Observable) 和 Retrofit2。我遇到了 Picasso 没有从 URL 加载图像的情况。详情如下:

public class IntentKeys {
    public static final long INTERCEPTOR_TIMEOUT = 15;
    public static final String POPULAR_MOVIES_SERVICE_ENDPOINT = "http://api.themoviedb.org/3/";
    public static final String POPULAR_MOVIES_POSTER_ENDPOINT = "http://image.tmdb.org/t/p/w300/";
    public static final String POPULAR_MOVIES_API_KEY = "key";

}

Recyclerview 适配器:

public class GridViewAdapter extends RecyclerView.Adapter<GridViewAdapter.GridVieHolder> {

    private static final String TAG = GridViewAdapter.class.getSimpleName();
    private static final int SPAN_COUNT = 2;
    private static final float THUMBNAIL_RATIO = 1.5f;
    private List<Result> movies = new ArrayList<>();
    private Context context;

    public GridViewAdapter(List<Result> movies, Context context) {
        this.movies = movies;
        this.context = context;
    }

    @Override
    public GridVieHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movies_grid_view, parent, false);
//        view.getLayoutParams().height = (int) (parent.getWidth() / SPAN_COUNT * THUMBNAIL_RATIO);
        return new GridVieHolder(view);
    }

    @Override
    public void onBindViewHolder(GridVieHolder holder, int position) {

        GridVieHolder posterHolder = (GridVieHolder) holder;
        posterHolder.bind(movies.get(position));

       /* Result popularMovies = movies.get(position);
        String moviePoster = popularMovies.getPosterPath();
        String moviePosterUrl = IntentKeys.POPULAR_MOVIES_POSTER_ENDPOINT + moviePoster;

        Picasso.with(context).load(moviePosterUrl.trim())
                .config(Bitmap.Config.RGB_565)
                .into(posters);*/
    }

    @Override
    public int getItemCount() {
        return movies.size();
    }

    public class GridVieHolder extends RecyclerView.ViewHolder {

        ImageView posters;

        public GridVieHolder(View itemView) {
            super(itemView);

            posters = (ImageView) itemView.findViewById(R.id.movies_poster_grid_view);
        }

        public void bind(final Result result) {


            Uri uri = Uri.parse(IntentKeys.POPULAR_MOVIES_POSTER_ENDPOINT).buildUpon()
                    .appendPath(ImageSize.w185.getValue())
                    .appendPath(result.getPosterPath().replace("/", ""))
                    .build();
            Picasso.with(itemView.getContext()).load(uri).into(posters);
        }
    }

}

下面是我定义服务和改造管理器的方式:

public interface PopularMoviesService {
    @GET("movie/popular")
    Observable<Result> getPopularMovies(@Query("api_key") String apiKey);
}

public class PopularMoviesRetrofitManager {


    private PopularMoviesService service;
    private static Retrofit retrofit = null;

    private static HttpLoggingInterceptor getLoggingInterceptor() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        return interceptor;
    }

    private static OkHttpClient getOkHttpClient(HttpLoggingInterceptor loggingInterceptor) {
        return new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .connectTimeout(IntentKeys.INTERCEPTOR_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(IntentKeys.INTERCEPTOR_TIMEOUT, TimeUnit.SECONDS)
                .build();
    }

    public static Retrofit getMoviesClient() {

        OkHttpClient client = getOkHttpClient(getLoggingInterceptor());

        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(IntentKeys.POPULAR_MOVIES_SERVICE_ENDPOINT)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(client)
                    .build();
        }
        return retrofit;
    }

}

最后是适配器和 fragment 类。在 Activity 类中,我有 getSupportFragmentManager() 来加载 fragment 。

public class GridViewAdapter extends RecyclerView.Adapter<GridViewAdapter.GridVieHolder> {

    private static final String TAG = GridViewAdapter.class.getSimpleName();
    private static final int SPAN_COUNT = 2;
    private static final float THUMBNAIL_RATIO = 1.5f;
    private List<Result> movies = new ArrayList<>();
    private Context context;

    public GridViewAdapter(List<Result> movies, Context context) {
        this.movies = movies;
        this.context = context;
    }

    @Override
    public GridVieHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movies_grid_view, parent, false);
//        view.getLayoutParams().height = (int) (parent.getWidth() / SPAN_COUNT * THUMBNAIL_RATIO);
        return new GridVieHolder(view);
    }

    @Override
    public void onBindViewHolder(GridVieHolder holder, int position) {

        GridVieHolder posterHolder = (GridVieHolder) holder;
        posterHolder.bind(movies.get(position));

       /* Result popularMovies = movies.get(position);
        String moviePoster = popularMovies.getPosterPath();
        String moviePosterUrl = IntentKeys.POPULAR_MOVIES_POSTER_ENDPOINT + moviePoster;

        Picasso.with(context).load(moviePosterUrl.trim())
                .config(Bitmap.Config.RGB_565)
                .into(posters);*/
    }

    @Override
    public int getItemCount() {
        return movies.size();
    }

    public class GridVieHolder extends RecyclerView.ViewHolder {

        ImageView posters;

        public GridVieHolder(View itemView) {
            super(itemView);

            posters = (ImageView) itemView.findViewById(R.id.movies_poster_grid_view);
        }

        public void bind(final Result result) {


            Uri uri = Uri.parse(IntentKeys.POPULAR_MOVIES_POSTER_ENDPOINT).buildUpon()
                    .appendPath(ImageSize.w185.getValue())
                    .appendPath(result.getPosterPath().replace("/", ""))
                    .build();
            Picasso.with(itemView.getContext()).load(uri).into(posters);
        }
    }

}

public class PopularMoviesFragment extends Fragment {

    private static final String TAG = PopularMoviesFragment.class.getCanonicalName();
    private GridViewAdapter gridViewAdapter;
    private List<Result> resultItems = new ArrayList<>();;
    private Subscription movieSubscription;
    private RecyclerView recyclerView;
    private PopularMoviesService service
            = PopularMoviesRetrofitManager.getMoviesClient().create(PopularMoviesService.class);

    public PopularMoviesFragment() {
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_popular_movies, container, false);

        recyclerView = (RecyclerView) view.findViewById(R.id.popular_movies_recycler_view);
        recyclerView.setHasFixedSize(true);
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 2);
        recyclerView.setLayoutManager(layoutManager);

        gridViewAdapter = new GridViewAdapter(resultItems, getContext());
        recyclerView.setAdapter(gridViewAdapter);

        return (view);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Override
    public void onStart() {
        super.onStart();
        getMoviesSubscription();
    }

    private void getMoviesSubscription() {
        movieSubscription = service.getPopularMovies(IntentKeys.POPULAR_MOVIES_API_KEY)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Action1<Result>() {
                            @Override
                            public void call(Result popularMovies) {

                            }

                        }, new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {

                            }
                        }, new Action0() {
                            @Override
                            public void call() {
                                displayPosters();
                                Log.i(TAG, "getMoviesSubscription: Completed");
                            }
                        }
                );
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (movieSubscription != null && movieSubscription.isUnsubscribed()) {
            movieSubscription.unsubscribe();
        }
    }

    private void displayPosters() {
        gridViewAdapter = new GridViewAdapter(resultItems, getContext());
        recyclerView.setAdapter(gridViewAdapter);
        recyclerView.invalidate();
    }

}

问题是,Picasso 没有通过 API 调用将图像加载到 GridView 中。任何人都将不胜感激。

这是 JSON 格式:

{
   "page":1,
   "results":[
      {
         "poster_path":"\/5N20rQURev5CNDcMjHVUZhpoCNC.jpg",
         "adult":false,
         "overview":"Following the events of Age of Ultron, the collective governments of the world pass an act designed to regulate all superhuman activity. This polarizes opinion amongst the Avengers, causing two factions to side with Iron Man or Captain America, which causes an epic battle between former allies.",
         "release_date":"2016-04-27",
         "genre_ids":[
            28,
            53,
            878
         ],
         "id":271110,
         "original_title":"Captain America: Civil War",
         "original_language":"en",
         "title":"Captain America: Civil War",
         "backdrop_path":"\/rqAHkvXldb9tHlnbQDwOzRi0yVD.jpg",
         "popularity":49.819238,
         "vote_count":2787,
         "video":false,
         "vote_average":6.93
      },
      {
         "poster_path":"\/e1mjopzAS2KNsvpbpahQ1a6SkSn.jpg",

在这里,poster_path 是我应该从中获取图像的地方。

最后,我有以下控制台输出。我确实看到我收到了响应及其 200。此外,我确实收到了响应中的所有数据。以下是控制台输出。

在此先感谢您为我解决此问题提供的所有支持。

抱歉,我差点忘了布局:movies_grid_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/movies_poster_grid_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

这是日志:

D: ClassLoader referenced unknown path: /data/app/com.example.mchapagai-2/lib/x86_64
W: ClassLoader referenced unknown path: /data/app/com.example.mchapagai-2/lib/x86_64
W: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D: --> GET http://api.themoviedb.org/3/discover/movie?api_key=api_key http/1.1
D: --> END GET
D: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

   [ 09-13 04:50:41.940  9654: 9654 D/         ]
   HostConnection::get() New Host Connection established 0x7f16976bf100, tid 9654
D: <-- 200 OK http://api.themoviedb.org/3/discover/movie?api_key=api_key (239ms)
D: Access-Control-Allow-Origin: *
D: Cache-Control: public, max-age=21600
D: Content-Type: application/json;charset=utf-8
D: Date: Tue, 13 Sep 2016 15:17:15 GMT
D: Server: openresty
D: Vary: Accept-Encoding
D: X-RateLimit-Limit: 40
D: X-RateLimit-Remaining: 39
D: X-RateLimit-Reset: 1473779845
D: Connection: keep-alive
D: {"page":1,"results":[{"poster_path":"\/5N20rQURev5CNDcMjHVUZhpoCNC.jpg","adult":false,"overview":"Following the events of Age of Ultron, the collective governments of the world pass an act designed to regulate all superhuman activity. This polarizes opinion amongst the Avengers, causing two factions to side with Iron Man or Captain America, which causes an epic battle between former allies.","release_date":"2016-04-27","genre_ids":[28,53,878],"id":271110,"original_title":"Captain America: Civil War","original_language":"en","title":"Captain America: Civil War","backdrop_path":"\/rqAHkvXldb9tHlnbQDwOzRi0yVD.jpg","popularity":48.757871,"vote_count":2812,"video":false,"vote_average":6.92},{"poster_path":"\/e1mjopzAS2KNsvpbpahQ1a6SkSn.jpg","adult":false,"overview":"From DC Comics comes the Suicide Squad, an antihero team of incarcerated supervillains who act as deniable assets for the United States government, undertaking high-risk black ops missions in exchange for commuted prison sentences.","release_date":"2016-08-03","genre_ids":[28,80,14],"id":297761,"original_title":"Suicide Squad","original_language":"en","title":"Suicide Squad","backdrop_path":"\/ndlQ2Cuc3cjTL7lTynw6I4boP4S.jpg","popularity":31.257563,"vote_count":1805,"video":false,"vote_average":5.9},{"poster_path":"\/zSouWWrySXshPCT4t3UKCQGayyo.jpg","adult":false,"overview":"After the re-emergence of the world's first mutant, world-destroyer Apocalypse, the X-Men must unite to defeat his extinction level plan.","release_date":"2016-05-18","genre_ids":[28,12,14,878],"id":246655,"original_title":"X-Men: Apocalypse","original_language":"en","title":"X-Men: Apocalypse","backdrop_path":"\/oQWWth5AOtbWG9o8SCAviGcADed.jpg","popularity":25.105112,"vote_count":1737,"video":false,"vote_average":6.1},{"poster_path":"\/tgfRDJs5PFW20Aoh1orEzuxW8cN.jpg","adult":false,"overview":"Arthur Bishop thought he had put his murderous past behind him when his most formidable foe kidnaps the love of his life. Now he is forced to travel the globe to complete three impossible assassinations, and do what he does best, make them look like accidents.","release_date":"2016-08-25","genre_ids":[80,28,53],"id":278924,"original_title":"Mechanic: Resurrection","original_language":"en","title":"Mechanic: Resurrection","backdrop_path":"\/3oRHlbxMLBXHfMqUsx1emwqiuQ3.jpg","popularity":23.569722,"vote_count":249,"video":false,"vote_average":4.45},{"poster_path":"\/h28t2JNNGrZx0fIuAw8aHQFhIxR.jpg","adult":false,"overview":"A recently cheated on married woman falls for a younger man who has moved in next door, but their torrid affair soon takes a dangerous turn.","release_date":"2015-01-23","genre_ids":[53],"id":241251,"original_title":"The Boy Next Door","original_language":"en","title":"The Boy Next Door","backdrop_path":"\/vj4IhmH4HCMZYYjTMiYBybTWR5o.jpg","popularity":23.27805,"vote_count":710,"video":false,"vote_average":4.03},{"poster_path":"\/5BCpxPLyp4wGcTribpZ6WtNkVJ5.jpg","adult":false,"overview":"After supervillain Shredder escapes custody, he joins forces with mad scientist Baxter Stockman and two dimwitted henchmen, Bebop and Rocksteady, to unleash a diabolical plan to take over the world. As the Turtles prepare to take on Shredder and his new crew, they find themselves facing an even greater evil with similar intentions: the notorious Krang.","release_date":"2016-06-01","genre_ids":[28,12,35,878],"id":308531,"original_title":"Teenage Mutant Ninja Turtles: Out of the Shadows","original_language":"en","title":"Teenage Mutant Ninja Turtles: Out of the Shadows","backdrop_path":"\/999RuhZvog8ocyvcccVV9yGmMjL.jpg","popularity":19.58401,"vote_count":285,"video":false,"vote_average":5.45},{"poster_path":"\/lw0IqOSMsQcy1QnVIEIDppLmNwk.jpg","adult":false,"overview":"A group of teens break into a blind man's home thinking they'll get away with the perfect crime. They're wrong.","release_date":"2016-08-25","genre_ids":[27,53],"id":300669,"original_title":"Don't Breathe","original_language":"en","title":"Don't B
D: reathe","backdrop_path":"\/bCThHXQ3aLLDU3KFST0rC8mTan5.jpg","popularity":17.777405,"vote_count":120,"video":false,"vote_average":5.99},{"poster_path":"\/hU0E130tsGdsYa4K9lc3Xrn5Wyt.jpg","adult":false,"overview":"One year after outwitting the FBI and winning the public’s adulation with their mind-bending spectacles, the Four Horsemen resurface only to find themselves face to face with a new enemy who enlists them to pull off their most dangerous heist yet.","release_date":"2016-06-02","genre_ids":[28,12,35,80,9648,53],"id":291805,"original_title":"Now You See Me 2","original_language":"en","title":"Now You See Me 2","backdrop_path":"\/zrAO2OOa6s6dQMQ7zsUbDyIBrAP.jpg","popularity":17.576621,"vote_count":861,"video":false,"vote_average":6.63},{"poster_path":"\/kqjL17yufvn9OVLyXYpvtyrFfak.jpg","adult":false,"overview":"An apocalyptic story set in the furthest reaches of our planet, in a stark desert landscape where humanity is broken, and most everyone is crazed fighting for the necessities of life. Within this world exist two rebels on the run who just might be able to restore order. There's Max, a man of action and a man of few words, who seeks peace of mind following the loss of his wife and child in the aftermath of the chaos. And Furiosa, a woman of action and a woman who believes her path to survival may be achieved if she can make it across the desert back to her childhood homeland.","release_date":"2015-05-13","genre_ids":[28,12,878,53],"id":76341,"original_title":"Mad Max: Fury Road","original_language":"en","title":"Mad Max: Fury Road","backdrop_path":"\/tbhdm8UJAb4ViCTsulYFL3lxMCd.jpg","popularity":15.943655,"vote_count":5310,"video":false,"vote_average":7.25},{"poster_path":"\/lFSSLTlFozwpaGlO31OoUeirBgQ.jpg","adult":false,"overview":"The most dangerous former operative of the CIA is drawn out of hiding to uncover hidden truths about his past.","release_date":"2016-07-27","genre_ids":[28,53],"id":324668,"original_title":"Jason Bourne","original_language":"en","title":"Jason Bourne","backdrop_path":"\/AoT2YrJUJlg5vKE3iMOLvHlTd3m.jpg","popularity":15.732751,"vote_count":824,"video":false,"vote_average":5.39},{"poster_path":"\/6vuxwCfBejPfUjMxrPgk0ANmVFq.jpg","adult":false,"overview":"An injured surfer stranded on a buoy needs to get back to shore, but the great white shark stalking her might have other ideas.","release_date":"2016-06-24","genre_ids":[27,18,53],"id":332567,"original_title":"The Shallows","original_language":"en","title":"The Shallows","backdrop_path":"\/lEkHdk4g0nAKtMcHBtSmC1ON3O1.jpg","popularity":15.369931,"vote_count":273,"video":false,"vote_average":6.13},{"poster_path":"\/nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg","adult":false,"overview":"Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.","release_date":"2014-11-05","genre_ids":[12,18,878],"id":157336,"original_title":"Interstellar","original_language":"en","title":"Interstellar","backdrop_path":"\/xu9zaAevzQ5nnrsXN6JcahLnG4i.jpg","popularity":15.24346,"vote_count":5678,"video":false,"vote_average":8.11},{"poster_path":"\/y31QB9kn3XSudA15tV7UWQ9XLuW.jpg","adult":false,"overview":"Light years from Earth, 26 years after being abducted, Peter Quill finds himself the prime target of a manhunt after discovering an orb wanted by Ronan the Accuser.","release_date":"2014-07-30","genre_ids":[28,878,12],"id":118340,"original_title":"Guardians of the Galaxy","original_language":"en","title":"Guardians of the Galaxy","backdrop_path":"\/bHarw8xrmQeqf3t8HpuMY7zoK4x.jpg","popularity":14.648276,"vote_count":5075,"video":false,"vote_average":7.96},{"poster_path":"\/jjBgi2r5cRt36xF6iNUEhzscEcb.jpg","adult":false,"overview":"Twenty-two years after the events of Jurassic Park, Isla Nublar now features a fully functioning dinosaur theme park, Jurassic World, as originally envisioned by John Hammond.","release_
D: date":"2015-06-09","genre_ids":[28,12,878,53],"id":135397,"original_title":"Jurassic World","original_language":"en","title":"Jurassic World","backdrop_path":"\/dkMD5qlogeRMiEixC4YNPUvax2T.jpg","popularity":14.280376,"vote_count":4987,"video":false,"vote_average":6.59},{"poster_path":"\/ckrTPz6FZ35L5ybjqvkLWzzSLO7.jpg","adult":false,"overview":"The peaceful realm of Azeroth stands on the brink of war as its civilization faces a fearsome race of invaders: orc warriors fleeing their dying home to colonize another. As a portal opens to connect the two worlds, one army faces destruction and the other faces extinction. From opposing sides, two heroes are set on a collision course that will decide the fate of their family, their people, and their home.","release_date":"2016-05-25","genre_ids":[28,12,14],"id":68735,"original_title":"Warcraft","original_language":"en","title":"Warcraft","backdrop_path":"\/5SX2rgKXZ7NVmAJR5z5LprqSXKa.jpg","popularity":13.977208,"vote_count":741,"video":false,"vote_average":6.13},{"poster_path":"\/vOipe2myi26UDwP978hsYOrnUWC.jpg","adult":false,"overview":"After a threat from the tiger Shere Khan forces him to flee the jungle, a man-cub named Mowgli embarks on a journey of self discovery with the help of panther, Bagheera, and free spirited bear, Baloo.","release_date":"2016-04-07","genre_ids":[12,18,14],"id":278927,"original_title":"The Jungle Book","original_language":"en","title":"The Jungle Book","backdrop_path":"\/eIOTsGg9FCVrBc4r2nXaV61JF4F.jpg","popularity":13.822341,"vote_count":1211,"video":false,"vote_average":6.35},{"poster_path":"\/gj282Pniaa78ZJfbaixyLXnXEDI.jpg","adult":false,"overview":"Katniss Everdeen reluctantly becomes the symbol of a mass rebellion against the autocratic Capitol.","release_date":"2014-11-18","genre_ids":[878,12,53],"id":131631,"original_title":"The Hunger Games: Mockingjay - Part 1","original_language":"en","title":"The Hunger Games: Mockingjay - Part 1","backdrop_path":"\/83nHcz2KcnEpPXY50Ky2VldewJJ.jpg","popularity":13.696672,"vote_count":3218,"video":false,"vote_average":6.69},{"poster_path":"\/cGOPbv9wA5gEejkUN892JrveARt.jpg","adult":false,"overview":"Fearing the actions of a god-like Super Hero left unchecked, Gotham City’s own formidable, forceful vigilante takes on Metropolis’s most revered, modern-day savior, while the world wrestles with what sort of hero it really needs. And with Batman and Superman at war with one another, a new threat quickly arises, putting mankind in greater danger than it’s ever known before.","release_date":"2016-03-23","genre_ids":[28,12,14],"id":209112,"original_title":"Batman v Superman: Dawn of Justice","original_language":"en","title":"Batman v Superman: Dawn of Justice","backdrop_path":"\/vsjBeMPZtyB7yNsYY56XYxifaQZ.jpg","popularity":13.659184,"vote_count":3614,"video":false,"vote_average":5.52},{"poster_path":"\/inVq3FRqcYIRl2la8iZikYYxFNR.jpg","adult":false,"overview":"Based upon Marvel Comics’ most unconventional anti-hero, DEADPOOL tells the origin story of former Special Forces operative turned mercenary Wade Wilson, who after being subjected to a rogue experiment that leaves him with accelerated healing powers, adopts the alter ego Deadpool. Armed with his new abilities and a dark, twisted sense of humor, Deadpool hunts down the man who nearly destroyed his life.","release_date":"2016-02-09","genre_ids":[28,12,35,10749],"id":293660,"original_title":"Deadpool","original_language":"en","title":"Deadpool","backdrop_path":"\/nbIrDhOtUpdD9HKDBRy02a8VhpV.jpg","popularity":13.637572,"vote_count":4967,"video":false,"vote_average":7.17},{"poster_path":"\/oDL2ryJ0sV2bmjgshVgJb3qzvwp.jpg","adult":false,"overview":"The city needs heroes. Darkness has settled over New York City as Shredder and his evil Foot Clan have an iron grip on everything from the police to the politicians. The future is grim until four unlikely outcast brothers rise from the sewers and discover their destiny as Teenage Mutant Ninja Turtles. The Turtles must work w
D: ith fearless reporter April and her wise-cracking cameraman Vern Fenwick to save the city and unravel Shredder's diabolical plan.","release_date":"2014-08-07","genre_ids":[878,28,12,14,35],"id":98566,"original_title":"Teenage Mutant Ninja Turtles","original_language":"en","title":"Teenage Mutant Ninja Turtles","backdrop_path":"\/OqCXGt5nl1cHPeotxCDvXLLe6p.jpg","popularity":13.480196,"vote_count":1660,"video":false,"vote_average":5.9}],"total_results":279563,"total_pages":13979}
D: <-- END HTTP (12492-byte body)
I: getMoviesSubscription: Completed

   [ 09-13 04:50:42.309  9654: 9699 D/         ]
   HostConnection::get() New Host Connection established 0x7f16a00bffc0, tid 9699
I: Initialized EGL, version 1.4
W: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
D: Poster URL: http://image.tmdb.org/t/p/w185/null
D: Dispatcher  enqueued     [R0]+108ms 
D: Hunter      executing    [R0]+156ms 
D: Dispatcher  batched      [R0]+320ms for error
D: Dispatcher  delivered    [R0]+560ms 
D: Main        errored      [R0]+560ms 

最佳答案

我现在明白了,至少我知道我错过了 onBindViewHolder: http://image.tmdb.org/t/p/w300/null这是没有得到 posterPath 的 Picasso URL .我将不得不找出为什么我得到的是 null 而不是图像。至少,这意味着订阅工作正常。

我将致力于 Picasso URL 修复。

我遗漏了什么:我忘记在 Action1<> 中添加数组列表Subscription的来电.这是我对订阅方法所做的更改:

  private void getMoviesSubscription() {
        movieSubscription = service.getPopularMovies(IntentKeys.POPULAR_MOVIES_API_KEY)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        new Action1<Result>() {
                            @Override
                            public void call(Result popularMovies) {
                                resultItems.add(popularMovies);
                            }

                        }, new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {

                            }
                        }, new Action0() {
                            @Override
                            public void call() {
                                displayPosters();
                                Log.i(TAG, "getMoviesSubscription: Completed");
                            }
                        }
                );
    }

关于android - 图像未使用 Rx Observable 和 Retrofit2 加载 Picasso,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39461958/

相关文章:

android - 使用 EditText 在 RecyclerView 中搜索

android - 错误 : The specified child already has a parent. 您必须先在 child 的 parent 上调用 removeView()

java - #Askfirebase 在 android 中的 firebase 回收器适配器中获取上一个项目值(POJO)

java - 如何使用Picasso打开android本地存储的图片?

java - 如果数据打开,则不会创建套接字

android - 如何禁用/抑制 IDEA "Rendering problems"警告

java - 为什么一开始启动应用程序时我的回收 View 没有显示?

java - 使用 picasso 将图像大小调整为全宽和固定高度

Android - StaggeredGrid 错误项目处置

java - 在不返回 JSON 字符串的 Android 中使用 HttpPost 进行 POST,返回错误