Reputation: 4217
My ListView
have multiple items. Each Item have a TextView
and two ImageView
. I have implemented this by using custom adapter. Each ImageView
in my ListView
have 5 images. How can i show 5 images repeatedly in a ImageView
in custom adapter? I want to repeat the images in all ImageView
in the interval of 15 seconds.
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;
}
}
Upvotes: 1
Views: 123
Reputation: 39406
The AnimationDrawable is the right component for that:
In your getView()
, I assume you have an ImageView
named imageView
. I also assume you have an array of Drawables representing your images:
AnimationDrawable animation = new AnimationDrawable();
for (Drawable image : images) {
animation.addFrame(image, 15 * 1000L);
}
imageView.setImageDrawable(animation);
animation.start();
This can change depending on how your images are available in your application.
Upvotes: 2
Reputation: 24181
let's say that you have the ids of your images in an array.
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();
Upvotes: 0
Reputation: 1609
You can spawn thread in getView
function for each ListView
item and put delay of 15 sec in between images.
like this:
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();
Upvotes: 0