本人小白,剛做完一個新聞客戶端,但是目前列表中的圖片會隨意的刷新顯示,慢慢下滑刷新列表的話會好一點,我覺得是適配器更新問題。
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 解決方法