我的ListView
有多个项目。每个项目都有TextView
和两个ImageView
。我已经使用自定义适配器实现了这一点。我ImageView
中的每个ListView
都有5张图片。如何在自定义适配器的ImageView
中重复显示5个图像?我希望在15秒的间隔内重复所有ImageView
中的图像。
public class CategoryAdapter extends BaseAdapter {
public Activity adapterActivity;
LayoutInflater adapterInflater;
ImageLoader compImageLoader;
List<Categary> list;
ArrayList<String> category = new ArrayList<String>();
ArrayList<String> leftImage = new ArrayList<String>();
ArrayList<String> rightImage = new ArrayList<String>();
public CategoryAdapter(Activity activity, List<Categary> listData) {
list = listData;
adapterActivity = activity;
adapterInflater = (LayoutInflater) adapterActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
compImageLoader = new ImageLoader(
adapterActivity.getApplicationContext());
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public class ViewHolder {
public ImageView lPic, rPic;
public TextView category;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder;
if (vi == null) {
vi = adapterInflater.inflate(R.layout.categoryadapter, null);
holder = new ViewHolder();
holder.lPic = (ImageView) vi.findViewById(R.id.imageView1);
holder.rPic = (ImageView) vi.findViewById(R.id.imageView2);
holder.category = (TextView) vi
.findViewById(R.id.textView_category);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
final Categary assingValue = list.get(position);
holder.lPic.setTag(assingValue.leftPicture);
holder.rPic.setTag(assingValue.rightPicture);
holder.category.setText(assingValue.id);
compImageLoader.DisplayImage(assingValue.leftPicture, holder.lPic);
compImageLoader.DisplayImage(assingValue.rightPicture, holder.rPic);
return vi;
}
}
答案 0 :(得分:2)
AnimationDrawable是正确的组成部分:
在getView()
中,我假设您有一个名为ImageView
的{{1}}。我还假设你有一个代表你的图像的Drawables数组:
imageView
根据应用程序中图像的可用方式,这可能会发生变化。
答案 1 :(得分:0)
您可以在getView
函数中为每个ListView
项生成线程,并在图像之间放置15秒的延迟。
final ImageView iv = (ImageView) v.findViewById(R.id.myImageView);
new Thread(new Runnable() {
@Override
public void run() {
while(true){
iv.setImageResource(iconID);
Thread.sleep(15000);
}
}
}).start();
答案 2 :(得分:0)
假设您将图像的ID放在数组中。
int i=0;
new CountDownTimer(15000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
@Override
public void onFinish() {
imgView.setImageResource(arrayIds[i]);
i++;
if(i==arrayIds.length)
i=0;
start();//restart the count down timer for another 15 seconds again
}
}.start();