QQ863017854
QQ863017854
2016-02-20 02:34

Android listview中的图片不停的刷新 并会随意显示

1
  • android
  • json
  • 适配器更新

本人小白,刚做完一个新闻客户端,但是目前列表中的图片会随意的刷新显示,慢慢下滑刷新列表的话会好一点,我觉得是适配器更新问题。

 public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.news_item, null);
        }

        TextView Title = (TextView) convertView.findViewById(R.id.Title);
        TextView date = (TextView) convertView.findViewById(R.id.date);
        TextView comment_count = (TextView)convertView.findViewById(R.id.comment_count);
        ImageView thumb_value = (ImageView) convertView.findViewById(R.id.thumb_value);
        News news = newsList.get(position);
        Title.setText(news.getTitle());
        date.setText("发布于"+news.getDate());
        comment_count.setText(news.getComment_count()+"条评论");
        String picUrl = news.getPicUrl();
        thumb_value.setTag( picUrl);//这个怎么调用???
        HttpUtils.setPicBitmap(thumb_value,picUrl);

        return convertView;
    }


    加载:
        public static void setPicBitmap(final ImageView thumb_value, final String picUrl){

        new Thread(new Runnable() {
            @Override
            public void run() {

                try {

                    HttpURLConnection conn = (HttpURLConnection) new URL(picUrl).openConnection();
                    conn.connect();
                    InputStream is = conn.getInputStream();
                    Bitmap bitmap = BitmapFactory.decodeStream(is);
                    thumb_value.setImageBitmap(bitmap);
                    is.close();
                } catch (Exception e) {
                    e.printStackTrace();
                } 
            }
        }).start();try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }

    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

6条回答

为你推荐