1

I have a Bitmap array in android, now I need to add this array to an ArrayList. I did this like

ArrayList<Bitmap> bmp_images = new ArrayList<Bitmap>(Arrays.asList(bmp));

But it showing an error The constructor ArrayList(List) is undefined

where bmp is the Bitmap array. What should i do please someone help me to fix this

Hybrid Developer
  • 2,320
  • 1
  • 34
  • 55

3 Answers3

4

Hope this can help you.

ArrayList<Bitmap> bmp_images = new ArrayList<Bitmap>();
for(int i = 0; i < bmp.length ;i++ ){
     bmp_images.add(bmp[i]);
}
ravi
  • 2,722
  • 7
  • 25
  • 42
  • 1
    so whats wrong with `ArrayList bmp_images = new ArrayList(Arrays.asList(bmp));`??? – Gopal Gopi Jun 03 '14 at 06:21
  • -1 Is this really necessary? The code OP posted is good Java. Is there a concrete reason it can't work on Android? If so, that should be part of your answer. If not, I would *never* recommend using a loop where there is a library function available, and neither should you. – drew moore Jun 03 '14 at 06:21
  • @GopalRaonothing wrong with it thankyou – Hybrid Developer Jun 03 '14 at 06:27
0

You can add every single item one by one or you can consider using Collections.addAll.

David Yee
  • 3,515
  • 25
  • 45
0

You can simply use (assuming bmp is Bitmap[])

List<Bitmap> bmp_images = Arrays.asList(bmp);

And there is no need for creating a copy of this collection (depending on your needs)

But it seems you have some problems with declarations of bmp array, so inspect that part.

Prizoff
  • 4,486
  • 4
  • 41
  • 69