Viewpager not getting positions properly

تعرفه تبلیغات در سایت
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس

جستجوگر

یافته ها در جستجو

    امکانات وب

    آرشیو مطالب

    برچسب ها

    Vote count: 0

    Hi i am using viewpager in my app. I am setting image arraylist in my viewpager. It shows images. but when i click on below button and check for its photoid, it shows wrong photoid. Following is my json reponse and and code. can any one help me.

    JSON RESPONSE

    {"success":1,"photos":[{"photo_id":"13","photo_path":"zMA.jpg"},{"photo_id":"12","photo_path":"H.jpg"},{"photo_id":"11","photo_path":"830.jpg"},{"photo_id":"10","photo_path":"hed.png"},{"photo_id":"9","photo_path":"med.png"},{"photo_id":"7","photo_path":"576.jpg"},{"photo_id":"6","photo_path":"im.jpg"},{"photo_id":"5","photo_path":"di3.jpg"},{"photo_id":"4","photo_path":"fb.jpg"}]}

    private void init() {
    
            mPager = (ViewPager) findViewById(R.id.pager);
            slidesadapter = new SlidingImage_Adapter(PhotoSlidersActivity.this,imageModelArrayList);
            slidesadapter.notifyDataSetChanged();
            mPager.setAdapter(slidesadapter);
    
    
            leftNav = (ImageButton) findViewById(R.id.left_nav);
            rightNav = (ImageButton) findViewById(R.id.right_nav);
    
    // Images left navigation
            leftNav.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int tab = mPager.getCurrentItem();
                    if (tab > 0) {
                        tab--;
                        mPager.setCurrentItem(tab);
                    } else if (tab == 0) {
                        mPager.setCurrentItem(tab);
                    }
                }
            });
    
            // Images right navigatin
            rightNav.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int tab = mPager.getCurrentItem();
                    tab++;
    
                    mPager.setCurrentItem(tab);
                }
            });
    
            final float density = getResources().getDisplayMetrics().density;
    
    
    
            NUM_PAGES =imageModelArrayList.size();
    
            // Auto start of viewpager
            final Handler handler = new Handler();
            final Runnable Update = new Runnable() {
                public void run() {
                    if (currentPage == NUM_PAGES) {
                        currentPage = 0;
                    }
                    mPager.setCurrentItem(currentPage++, true);
                }
            };
    
    
            // Pager listener over indicator
    
    
        }
    
        public class SlidingImage_Adapter extends PagerAdapter {
    
    
            private ArrayList imageModelArrayList;
            private LayoutInflater inflater;
            private Context context;
    
    
            public SlidingImage_Adapter(Context context, ArrayList imageModelArrayList) {
                this.context = context;
                this.imageModelArrayList = imageModelArrayList;
                inflater = LayoutInflater.from(context);
            }
    
            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }
    
            @Override
            public int getCount() {
                return imageModelArrayList.size();
            }
    
            @Override
            public Object instantiateItem(ViewGroup view, final int position) {
                View imageLayout = inflater.inflate(R.layout.slider, view, false);
    
                assert imageLayout != null;
                final ImageView imageView = (ImageView) imageLayout
                        .findViewById(R.id.image);
    
    
               // imageView.setImageResource(imageModelArrayList.get(position).getPhotopath());
    
                Picasso.with(PhotoSlidersActivity.this)
                        .load(imageModelArrayList.get(position).getPhotopath())
                        .into(imageView);
    
                shareimage.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
    
                        String shareimg=imageModelArrayList.get(position).getPhotopath();
                        System.out.println("Added"+imageModelArrayList.get(position).getPhotoid());
                       // shareItem(shareimg);
    
                    }
                });
                view.addView(imageLayout, 0);
    
                return imageLayout;
            }
    
            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view.equals(object);
            }
    
            @Override
            public void restoreState(Parcelable state, ClassLoader loader) {
            }
    
            @Override
            public Parcelable saveState() {
                return null;
            }
    
            @Override
            public int getItemPosition(Object object) {
                return POSITION_NONE;
            }
        }
    

    When image with id 13 is visible on my screen, and when i click on share button it shows id 12 instead of 13. can any one help me to solve this.

    Thanks

    asked 1 min ago
    Nilima

    نویسنده : استخدام کار بازدید : 6 تاريخ : چهارشنبه 25 بهمن 1396 ساعت: 12:59
    برچسب‌ها :
    اخبار و رسانه هاهنر و ادبیاترایانه و اینترنتعلم و فن آوریتجارت و اقتصاداندیشه و مذهبفوتو بلاگوبلاگ و وبلاگ نویسیفرهنگ و تاریخجامعه و سیاستورزشسرگرمی و طنزشخصیخانواده و زندگیسفر و توریسمفارسی زبان در دیگر کشورها