1

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

  item = new ArrayList<String>();
   item.add("an image");
3
  • 1
    ArrayList<String> can only hold Strings. You can store, say, the path to the image as a string, or perhaps the image itself encoded in base64. Which are you trying to do? If it's the latter, make it an ArrayList<File> or ArrayList<Image>. Commented Jan 21, 2012 at 7:27
  • I tried giving the path..but the output was some kind of number, maybe resource id...not an image.. Commented Jan 21, 2012 at 7:41
  • This is really useful for this question: technotalkative.com/android-gridview-example Commented May 6, 2012 at 10:21

3 Answers 3

3

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 

 }
Sign up to request clarification or add additional context in comments.

1 Comment

try adding a basic explanation, it'll help them better understand it :).
1

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.

Comments

0

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.