Reth
Reth

Reputation: 67

How to add image to ArrayList<string> in android?

I need to add an image into "item". item is an xml file with TextView...

  item = new ArrayList<String>();
   item.add("an image");

Upvotes: 1

Views: 6336

Answers (3)

Mercy
Mercy

Reputation: 1860

Try this code

ArrayList<Bitmap> mBit = new ArrayList<Bitmap>(9);
for (int i = 0; i < 9; i++)
{
mBit.add(Bitmap.createBitmap(bitmapOrg, (i % 3) * newWidth, (i / 3) * newHeight,       newWidth, newHeight));
}
Collections.shuffle(mBit);

for (int i = 0; i < 10; i++)
{
Bitmap bitmap = mBit.get(i));

//Do something here 

 }

Upvotes: 3

Samet
Samet

Reputation: 917

You should create an ArrayList of objects and you can put everything you want in it and manipulate like this :

ArrayList<Object> array = new ArrayList<Object>();

array.put(0,"A string");
array.put(1,yourbitmap);

String string = (String) array.get(0);
Bitmap bitmap = (Bitmap) array.get(1);

You must cast when you get get because it is an object array.

Upvotes: 1

Shashank Kadne
Shashank Kadne

Reputation: 8101

If by image, you mean an image File and not Image object. Then use

add(fileObject.toString())

and while retrieving recreate File object using that object String.

new File(array.get(0)).getPath()

Upvotes: 0

Related Questions