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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!