How to populate dynamically created imageview thro

2019-08-30 18:23发布

问题:

I am using horizontal pager

https://github.com/ysamlan/horizontalpager/blob/master/src/com/github/ysamlan/horizontalpager/HorizontalPager.java

to make dynamic views,and making dynamic images in it....

And using fedor imageloader to pupulate imageviews from urls... https://github.com/thest1/LazyList/blob/master/src/com/fedorvlasov/lazylist/ImageLoader.java

but i am getting that annoying stid image.... here is my code...

Any help or suggestion will be highly appropriated

Thanx in advance

public class testing extends Activity {

private HorizontalPager mPager;
 ImageView[] image;

 String url = "http://icons-search.com/img/icons-land/IconsLandVistaStyleEmoticonsDemo.zip/IconsLandVistaStyleEmoticonsDemo-PNG-256x256-Cool.png-256x256.png";

 @Override
 public void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.testing);
  ImageLoader imageLoader = new ImageLoader(this);
  mPager = (HorizontalPager) findViewById(R.id.horizontal_pager);

  image = new ImageView[2];
  for (int i = 0; i < 2; i++) {

   image[i] = new ImageView(getApplicationContext());
   image[i].setImageResource(R.drawable.logo_background);
   RelativeLayout.LayoutParams layoutParams90 = new RelativeLayout.LayoutParams(
     225, 250);
   layoutParams90.leftMargin = 25;
   image[i].setLayoutParams(layoutParams90);
   mPager.addView(image[i]);

  }

  for (int i = 0; i < 2; i++) {
   imageLoader.DisplayImage(url, image[i]);
  }
 }

}

回答1:

When you create ImageView try to pass your Activity instead of Application context. So replace this

image[i] = new ImageView(getApplicationContext());

with this

image[i] = new ImageView(this);


回答2:

Please check whether you added external storage and internet permission in your android manifest file?



回答3:

You need to localize the problem first. Probably there's something wrong with the url you use - try another one. Probably something related to Pager - try without pages, just put all images into LinearLayout. What else may be a problem - just find some clue. Does it work if you just put a single ImageView to the screen?