做了个列表listview 定时3秒每次添加两行数据,数据是每一行里包括一张图加文字,但是下面的代码每次把列表上的图片都重置了一下,红色icount是我传进来的外部调用添加listviewtf 的次数,每次两行,
或者是其它别的情况引起,新手提问
public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText>{
private ListView listView;
private AsyncImageLoader1 asyncImageLoader;
private int j;
public ImageAndTextListAdapter(Activity activity, List<ImageAndText> imageAndTexts, ListView listView ,int icount) {
super(activity, 0, imageAndTexts);
this.listView = listView;
asyncImageLoader = new AsyncImageLoader1();
this.j=icount;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("position的值是:" + position +"");
Activity activity = (Activity) getContext();
// Inflate the views from XML
View rowView = convertView;
ViewCache viewCache;
if (rowView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.bb, null);
viewCache = new ViewCache(rowView);
rowView.setTag(viewCache);
} else {
viewCache = (ViewCache) rowView.getTag();
}
ImageAndText imageAndText = getItem(position);
// Load the image and set it on the ImageView
String imageUrl = imageAndText.getImageUrl();
ImageView imageView = viewCache.getImageView();
imageView.setTag(imageUrl);
Drawable cachedImage = asyncImageLoader.loadDrawable(imageUrl, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
ImageView imageViewByTag = (ImageView) listView.findViewWithTag(imageUrl);
if (imageViewByTag != null) {
imageViewByTag.setImageDrawable(imageDrawable);
}
}
});
if (cachedImage == null) {
imageView.setImageResource(R.drawable.ic_launcher);
}else{
imageView.setImageDrawable(cachedImage);
}
// Set the text on the TextView
TextView textView = viewCache.getTextView();
textView.setText(imageAndText.getText());
return rowView;
}
}
------解决方案--------------------
方法是更改数组,然后adapter notifydatachange
------解决方案--------------------
嗯 这样就是会重新加载。。。。