リストビューにイメージスイッチャーを追加したいアプリに取り組んでいます。スイッチャーをスクロールしているときに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;
}
}
}