Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

android - Pager Adapter not displaying image after getting from response in fragment

I am getting three images from response,and i am storing in arraylist,then i try to set in PagerAdapter,but nothing display in my view pager,following is my pageradapter class,can any one tell that what is mistake i made?

I am using Fragment

In my Postexecute i am setting it in view pager like this

adapter = new ImageAdapter(All_Product_Details.this.getActivity());
            viewPager.setAdapter(adapter);
}

below is my adapter which i set after asynctask

      public class ImageAdapter extends FragmentPagerAdapter {
    Context context;
    ImageAdapter(Context context)
    {
        this.context=context;
    }
    @Override
    public int getCount() {
        return multimglist.size();
    }

    @Override
    public Fragment getItem(int i) {
        return null;
    }

    @Override
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }
    @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);
        int padding = context.getResources().getDimensionPixelSize(
                R.dimen.activity_horizontal_margin);
        imageView.setPadding(padding, padding, padding, padding);
        //imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        Picasso.with(context).load(multimglist.get(position)).into(imageView);


        // imageView.setImageURI(Uri.parse(imgStr[position]));
        ((ViewPager) container).addView(imageView, 0);
        return imageView;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
this is my pager adapter change according that
public class LoginViewPagerCA extends PagerAdapter {
    SparseArray<View> views = new SparseArray<>();
    List<Viewpager_POJO> listofPersons;
    LayoutInflater inflater;
    Context context;

    private int count = 4;
    public LoginViewPagerCA(Context context, List<Viewpager_POJO> listofPersons) {
        this.context = context;
        this.listofPersons = listofPersons;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return listofPersons.size();
    }
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public boolean isViewFromObject(View view, Object obj) {
        // TODO Auto-generated method stub
        return view == ((LinearLayout) obj);

    }
    public void setData(ArrayList<Viewpager_POJO> data) {
        listofPersons = data;
    }

    public Object instantiateItem(ViewGroup container, final int position)

    {

        final TextView txtFstName, txtLstName, txtRollno, txtArrTime, txtTimeLeft;
        ImageView imgView;

        final Viewpager_POJO rowperson = listofPersons.get(position);

        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View itemView = inflater.inflate(R.layout.landing_pager_item, container, false);
        txtFstName = (TextView) itemView.findViewById(R.id.pager_big_tv);
        txtLstName = (TextView) itemView.findViewById(R.id.pager_small_tv);
        imgView = (ImageView) itemView.findViewById(R.id.pager_image);


        try {
            // txtCompn.setText((position + 1) + "/" + StuFirstNM.length);
            txtFstName.setText(rowperson.getDesc());
            txtLstName.setText(rowperson.getRating());

            //new LoadImage(imgView).execute(rowperson.getUrls());
            if (!TextUtils.isEmpty(rowperson.getUrls())) {
             //   PicassoTrustAll.getInstance(context).load(rowperson.getUrls()).placeholder(context.getResources().getDr`enter code here`awable(R.drawable.ic_launcher)).error(context.getResources().getDrawable(R.drawable.ic_launcher)).into(imgView);
//
                byte[] imgbytes = Base64.decode(rowperson.getStrImm(), Base64.DEFAULT);
                Bitmap bitmap = BitmapFactory.decodeByteArray(imgbytes, 0, imgbytes.length);
                imgView.setImageBitmap(bitmap);
//                PicassoTrustAll.getInstance(context)
//                        .load(rowperson.getUrls())
//                        .error(R.mipmap.landinglogo)
//                        .into(imgView);
                Log.w("Testing", "Image Download URL=" + rowperson.getUrls());
            } else {
                imgView.setBackgroundResource(R.mipmap.landinglogo);
            }


            ((ViewPager) container).addView(itemView);
            views.put(position, itemView);

        } catch (Exception e)

        {
            e.printStackTrace();
        }

        return itemView;
    }


    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;

        ((ViewPager) container).removeView(view);
        views.remove(position);
        view = null;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...