我正在开发一个应用程序,我想在Listview中添加图像切换器。当滚动切换器时,它会导致imageSwitcher中的图像混乱。我谷歌很多次但没有得到任何使用完整的教程
我的代码是:
public View getView(int position, View convertView, ViewGroup parent) {
holder = new ImageHolder();
/**
* layout and its component Initialization
*/
convertView = inflater.inflate(R.layout.selectedtopicitem, parent,
false);
holder.profilename = (TextView) convertView
.findViewById(R.id.profilename);
imageList = new ArrayList<String>();
holder.postid = (TextView) convertView.findViewById(R.id.postid);
holder.posttime = (TextView) convertView.findViewById(R.id.posttime);
holder.commentedimagetext = (TextView) convertView
.findViewById(R.id.commentedimagetext);
holder.imagepost = (Gallery) convertView.findViewById(R.id.imagepost);
holder.imageSwitcher = (ImageSwitcher) convertView
.findViewById(R.id.switcher1);
holder.imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(
context, android.R.anim.fade_in));
holder.imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(
context, android.R.anim.fade_out));
/*setting adapter for imageswitcher*/
holder.imagepost.setAdapter(new ImageAdapter(context));
(new ImageAdapter(context)).notifyDataSetChanged();
return convertView;
}
/*adapter class*/
public class ImageAdapter extends BaseAdapter {
private Context context;
private int itemBackground;
public ImageAdapter(Context c) {
context = c;
// ---setting the style---
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
// ---returns the number of images---
public int getCount() {
return imageList.size();
}
// ---returns the ID of an item---
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
// ---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent) {
AQuery aq = new AQuery(context);
ImageView imageView = new ImageView(context);
imageView.setPadding(10, 0, 10, 0);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(display_width,
LayoutParams.WRAP_CONTENT));
try {
aq.id(imageView).image("http://" + imageList.get(position),
true, true, display_width, 0, null, AQuery.FADE_IN);
} catch (Exception e) {
e.printStackTrace();
}
return imageView;
}
}
}