I have downloaded a bunch of image from the internet with the following code:
for(int i = 1; i < 12; i++) {
try {
URL imageURL = new URL("http://domain/drawimage.php?type=" + i + "&d1=" + this.d1 + "&d2=" + this.d2);
Bitmap image = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
bitmaps.add(image);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
Later when I try to insert them into a LinearLayout (ll), the images won’t appear even though bitmaps.size() = 11.
for(int i = 0; i < bitmaps.size(); i++) {
ImageView iv = new ImageView(c); // c = getApplicationContext()
iv.setImageBitmap(bitmaps.get(i));
iv.setVisibility(ImageView.VISIBLE);
ll.addView(iv);
}
If I try with TextView, it works.
for(int i = 0; i < bitmaps.size(); i++) {
TextView tv = new TextView(c); // c = getApplicationContext()
tv.setText("image ");
tv.setGravity(Gravity.CENTER_HORIZONTAL);
ll.addView(tv);
}
Is the problem with the loading or does the insertation fail? How to fix?
I had problems printing out the picture on the PHP side. I should have checked that too. Now it’s working.