将 url 中的图像添加到第二和第三位置的 viewpager

add image from url to viewpager in second and third position

这里我有两个 url 但是当我 运行 这个应用程序时这个图像被加载到第二页意味着第一张图片将在几秒钟后加载到第二页第二张图片也添加到相同通过重叠定位。我需要将其添加到第二页和第三页 url

 viewPager = (ViewPager) findViewById(R.id.splash);
        ImageAdapter adapter = new ImageAdapter(this);
        viewPager.setAdapter(adapter);

public class ImageAdapter extends PagerAdapter {

        Context context;

        private int[] GalImages = new int[] {
                R.drawable.slider,
                R.drawable.slider,
                R.drawable.slider,
        };

        ImageAdapter(Context context){
            this.context=context;
        }

        @Override
        public int getCount() {
         return GalImages.length;
         //   return 10;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == ((ImageView) object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageView.setImageResource(GalImages[position]);
            new LoadImage(imageView).execute("http://www.gadgetbaazar.com/wp-content/uploads/2016/12/Top-Mobile-Phones.jpg");
            new LoadImage(imageView).execute("https://pisces.bbystatic.com/BestBuy_US/store/ee/2015/com/pm/nav_desktops_1115.jpg");
            container.addView(imageView, 0);
            return imageView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((ViewPager) container).removeView((ImageView) object);
        }



        private class LoadImage extends AsyncTask<String, String, Bitmap> {
            ImageView img=null;
            public LoadImage(ImageView img){
                this.img=img;
            }
            @Override
            protected void onPreExecute() {
                super.onPreExecute();

            }
            protected Bitmap doInBackground(String... args) {
                Bitmap bitmap=null;
                try {
                    bitmap = BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return bitmap;
            }
            protected void onPostExecute(Bitmap image) {
                if(image != null){
                    img.setImageBitmap(image);
                }
            }
        }
    }

试试这个

@Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            if(position == 0){
            imageView.setImageResource(GalImages[position]);
            }else if(position == 1){
            new LoadImage(imageView).execute("http://www.gadgetbaazar.com/wp-content/uploads/2016/12/Top-Mobile-Phones.jpg");
            }else if(position ==2){
            new LoadImage(imageView).execute("https://pisces.bbystatic.com/BestBuy_US/store/ee/2015/com/pm/nav_desktops_1115.jpg");
            }

            container.addView(imageView, 0);
            return imageView;
        }