QQ863017854 2016-02-20 02:34 采纳率: 100%
浏览 2390
已采纳

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

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

 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条回答 默认 最新

  • tzizi5566 2016-02-20 13:44
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知