4

Universal Imageloader api を使用しています。

ページャーを表示するために画像を表示したい..

しかし、instantiateItem メソッドが呼び出されていません...

これは私のクラスです

package com.primus.taukyuniversalimageloader;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;


import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

public class TaukypagerActivity extends BaseActvity {
    private static final String STATE_POSITION = "STATE_POSITION";

    DisplayImageOptions options;

    ViewPager pager;
    ArrayList<String> imageUrls;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tauky_image_pager);



        imageUrls=new ArrayList<String>();
        imageUrls = TaukyImageloader.image_takies;

        int pagerPosition = TaukyImageloader.click_position;

//      if (savedInstanceState != null) {
//          pagerPosition = savedInstanceState.getInt(STATE_POSITION);
//      }

        options = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.drawable.ic_launcher)
            .showImageOnFail(R.drawable.ic_launcher)
            .resetViewBeforeLoading()
            .cacheOnDisc()
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(300))
            .build();

        pager = (ViewPager) findViewById(R.id.pager);
        ImagePagerAdapter adapter=new ImagePagerAdapter(this,imageUrls);

        pager.setAdapter(adapter);
        pager.setCurrentItem(pagerPosition);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(STATE_POSITION, pager.getCurrentItem());
    }

    private class ImagePagerAdapter extends PagerAdapter {

        private ArrayList<String> images;
        private LayoutInflater inflater;

        ImagePagerAdapter(TaukypagerActivity taukypagerActivity, ArrayList<String> images) {

            this.images=new ArrayList<String>();
            this.images = images;

            inflater = getLayoutInflater();


        }

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


        @Override
        public int getCount() {

            return images.size();

        }

        @Override
        public Object instantiateItem(ViewGroup view, int position) {


            Log.i("Loading", "Entered into instatiate....");
            View imageLayout = inflater.inflate(R.layout.item_pager_image, view, false);
            final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
            final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);



            imageLoader.displayImage(images.get(position), imageView, options, new SimpleImageLoadingListener() {
                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    spinner.setVisibility(View.VISIBLE);


                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    String message = null;
                    switch (failReason.getType()) {
                        case IO_ERROR:
                            message = "Input/Output error";
                            break;
                        case DECODING_ERROR:
                            message = "Image can't be decoded";
                            break;
                        case NETWORK_DENIED:
                            message = "Downloads are denied";
                            break;
                        case OUT_OF_MEMORY:
                            message = "Out Of Memory error";
                            break;
                        case UNKNOWN:
                            message = "Unknown error";
                            break;
                    }
                    Toast.makeText(TaukypagerActivity.this, message, Toast.LENGTH_SHORT).show();

                    spinner.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    spinner.setVisibility(View.GONE);



                }
            });

            ((ViewPager) view).addView(imageLayout, 0);
            return imageLayout;
        }

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



        @Override
        public Parcelable saveState() {
            return null;
        }


    }
}

すべてのメソッドを自動的に呼び出しますが、instantiateItem(ViewGroup view, int position) はまだ呼び出していません.....

4

0 に答える 0