本人小白,刚做完一个新闻客户端,但是目前列表中的图片会随意的刷新显示,慢慢下滑刷新列表的话会好一点,我觉得是适配器更新问题。
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();
}
}
http://blog.csdn.net/guolin_blog/article/details/45586553 解决方法
求大神解答 !!!急
本人小白 刚下载此软件 ,不清楚
就是你代码写的有问题,好好查你的适配器
你是不是起线程来更新图片了,这是convertView复用机制的一个缺点,那样就在getView方法里给显示图片的ImageView对象设置一个标签(setTag()),在线程中更新图片之前先判断是否与当前图片的标签一致。
代码就那几行;
listview复用的问题。网上的解决办法很多,百度一下就知道。
http://blog.csdn.net/guolin_blog/article/details/45586553