Yet another getView called multiple times

后端 未结 5 1399
醉话见心
醉话见心 2020-11-28 11:57

Each item in my ListView containt an ImageView and a TextView, this will be filled with remote information.

I got an URL for t

相关标签:
5条回答
  • 2020-11-28 12:33

    I tried using fill_parent as height in ListView but i was unable to achieve it perfect but how ever i tried it by preventing creating convertViews if it its already exist. it works fine in my appoach.

            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
             if (convertView != null)
                return convertView;
             else {
                //your code...
             }
        }
    
    0 讨论(0)
  • 2020-11-28 12:38

    i recommend you to watch this video http://www.youtube.com/watch?v=wDBM6wVEO70

    basically android will call getView multiple times for it's calculation of view heights and stuff, so you need to implement some sort of cache in your async, check http://code.google.com/p/android-query/ which has that if you don't use authentication

    0 讨论(0)
  • 2020-11-28 12:48

    Sorry for late reply. I had been facing the same problem in my adapter for gallery widget. I had employed Universal Image Loader. Martijn's solution worked for me. What all I had to do was to add notifyDataSetChanged() when the image had been completely downloaded and imageView was being set.

    0 讨论(0)
  • 2020-11-28 12:49

    The problem was in the Layout of the ListView.

    The parameter layout_width was set to wrap_content when I changed it to fill_parent the problem disappeared...

    0 讨论(0)
  • 2020-11-28 12:53

    The problem is that your ListView does not know what the of each item is. When initializing, the ListView will measure all of its children and draw itself upon this information. What you are doing with your AsyncTask, is changing the sizes of the items in the list and not letting the ListView draw itself again completely. This results in your ListView to behave strangly.

    Solution: You should update your ListView by notifying the Adapter using notifyDataSetChanged() in the PostExecute of your AsyncTask. This will allow the ListView to draw itself with the new information.

    I hope it works !

    A few helpfull links:

    http://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/

    Lazy load of images in ListView

    0 讨论(0)
提交回复
热议问题