<legend id='WNJUJ'><style id='WNJUJ'><dir id='WNJUJ'><q id='WNJUJ'></q></dir></style></legend>
  1. <i id='WNJUJ'><tr id='WNJUJ'><dt id='WNJUJ'><q id='WNJUJ'><span id='WNJUJ'><b id='WNJUJ'><form id='WNJUJ'><ins id='WNJUJ'></ins><ul id='WNJUJ'></ul><sub id='WNJUJ'></sub></form><legend id='WNJUJ'></legend><bdo id='WNJUJ'><pre id='WNJUJ'><center id='WNJUJ'></center></pre></bdo></b><th id='WNJUJ'></th></span></q></dt></tr></i><div id='WNJUJ'><tfoot id='WNJUJ'></tfoot><dl id='WNJUJ'><fieldset id='WNJUJ'></fieldset></dl></div>
  2. <small id='WNJUJ'></small><noframes id='WNJUJ'>

    • <bdo id='WNJUJ'></bdo><ul id='WNJUJ'></ul>

      <tfoot id='WNJUJ'></tfoot>

      ViewPager 无法使用 Picasso 懒惰地加载图像

      时间:2023-10-03
        <bdo id='kHRUf'></bdo><ul id='kHRUf'></ul>

              <tbody id='kHRUf'></tbody>
              • <tfoot id='kHRUf'></tfoot>

                <i id='kHRUf'><tr id='kHRUf'><dt id='kHRUf'><q id='kHRUf'><span id='kHRUf'><b id='kHRUf'><form id='kHRUf'><ins id='kHRUf'></ins><ul id='kHRUf'></ul><sub id='kHRUf'></sub></form><legend id='kHRUf'></legend><bdo id='kHRUf'><pre id='kHRUf'><center id='kHRUf'></center></pre></bdo></b><th id='kHRUf'></th></span></q></dt></tr></i><div id='kHRUf'><tfoot id='kHRUf'></tfoot><dl id='kHRUf'><fieldset id='kHRUf'></fieldset></dl></div>

              • <legend id='kHRUf'><style id='kHRUf'><dir id='kHRUf'><q id='kHRUf'></q></dir></style></legend>

                <small id='kHRUf'></small><noframes id='kHRUf'>

                本文介绍了ViewPager 无法使用 Picasso 懒惰地加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 TabHost 的第一个选项卡中有一个 FragmentActivity,而 FragmentActivity 本身包含一个 ViewPager.

                I have a FragmentActivity in the first tab of a TabHost, and the FragmentActivity itself holds a ViewPager.

                ViewPagersetAdapter() 方法使用一组 Fragment 设置 FragmentPagerAdapter.目标是在 TabHost 的第一个窗格中显示可滑动的图像.

                The ViewPager's setAdapter() method sets a FragmentPagerAdapter with a set of Fragments. The goal is to have swipeable images in the first pane of the TabHost.

                为了测试它,我加载了我在项目的 drawable 目录中本地保存的一堆图像.一切都很顺利.

                To test it, I was loading a bunch of images that I had kept locally in the project's drawable directory. Everything worked beautifully.

                在测试了这个初始设置之后,我正在从 REST Web 服务下载一堆图像 URL.我希望这些图像在 ViewPager 中延迟加载,我尝试在三个地方调用 Picasso 的 load() 方法:

                After having tested this initial setup, I'm downloading a bunch of image URLs' off a REST web service. I want these images to load lazily in the ViewPager, and I tried calling Picasso's load() method in three places:

                1. ViewPagerFragmentonCreateView() 方法(与我之前从中加载图像的位置相同)本地 drawable 目录).

                1. The onCreateView() method of the ViewPager's Fragments (the same place where I was earlier loading images from the local drawable directory).

                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container, 
                    Bundle savedInstanceState) {                
                
                    View myFragmentView = inflater.inflate(R.layout.layout_fragment, container, false);
                
                    ImageView imageView = (ImageView)getView().findViewById(R.id.fragment_image);
                    String url = getArguments().getString(IMAGE_RESOURCE_URL);
                    Context context = getActivity();
                    Picasso.with(context).load(url).fit().into(imageView);
                
                    return myFragmentView;
                }
                

              • ViewPagerFragments的onViewCreated()方法.

                @Override
                public void onViewCreated(View view, Bundle savedInstanceState){
                
                    Context context = getActivity();
                    String url = getArguments().getString(IMAGE_RESOURCE_URL);
                    ImageView imageView = (ImageView)view.findViewById(R.id.fragment_image);
                    Picasso.with(context).load(url).fit().into(imageView);      
                
                }        
                

              • FragmentPagerAdapteronInstantiateItem()方法.

                @Override
                public Object instantiateItem(ViewGroup container, int position) {
                
                    View v = inflater.inflate(R.layout.layout_fragment, container, false);
                    Context context = Tab1Activity.this;
                    String url = getItem(position).getArguments().getString("IMAGE_RESOURCE_URL");
                    ImageView imageView = (ImageView)v.findViewById(R.id.fragment_image);
                    Picasso.with(context).load(url).fit().into(imageView);
                    return v;
                }
                

              • 这些方法都不起作用.我知道毕加索不是问题,因为前几天我尝试在 ListView 中使用毕加索,它就像一个魅力.我做错了什么?

                None of these methods worked. I know that its not a problem with Picasso because the other day I tried using Picasso in a ListView and it worked like a charm. What am I doing wrong ?

                推荐答案

                您的第一种方法应该可以正常工作...如果您正确实施它.我希望您的代码会因 NullPointerException 而崩溃.

                Your first approach should work fine... if you implement it correctly. I would expect your code to crash with a NullPointerException.

                替换:

                ImageView imageView = (ImageView)getView().findViewById(R.id.fragment_image);
                

                与:

                ImageView imageView = (ImageView)myFragmentView.findViewById(R.id.fragment_image);
                

                这篇关于ViewPager 无法使用 Picasso 懒惰地加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Android 的 Fragment 中使用 Google 地图 下一篇:从 ViewPager 获取不同片段的值

                相关文章

                <i id='YtHrV'><tr id='YtHrV'><dt id='YtHrV'><q id='YtHrV'><span id='YtHrV'><b id='YtHrV'><form id='YtHrV'><ins id='YtHrV'></ins><ul id='YtHrV'></ul><sub id='YtHrV'></sub></form><legend id='YtHrV'></legend><bdo id='YtHrV'><pre id='YtHrV'><center id='YtHrV'></center></pre></bdo></b><th id='YtHrV'></th></span></q></dt></tr></i><div id='YtHrV'><tfoot id='YtHrV'></tfoot><dl id='YtHrV'><fieldset id='YtHrV'></fieldset></dl></div>

                    <tfoot id='YtHrV'></tfoot>
                  1. <legend id='YtHrV'><style id='YtHrV'><dir id='YtHrV'><q id='YtHrV'></q></dir></style></legend>
                    • <bdo id='YtHrV'></bdo><ul id='YtHrV'></ul>

                    <small id='YtHrV'></small><noframes id='YtHrV'>