chiuki / android-swipe-image-viewer

Android Image Viewer that moves to the previous and next images by swiping

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to Swipe Images When Used in Android App

Java-god opened this issue · comments

This works perfectly as a stand-alone android project, but when I try to implement it in my existing android app, the images do not swipe, it just remains static and does not respond to swipe gestures. Please help.

My app animates images in onCreate and I am trying manually swipe through the images in a menu item. I use different imageView names for animating in onCreate and for swiping images in the menu item (to make sure they're not trying to access the same imageView simultaneously.

`public void swipeWines() {
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    ImagePagerAdapter adapter = new ImagePagerAdapter();
    viewPager.setAdapter(adapter);
}

private class ImagePagerAdapter extends PagerAdapter implements
        com.safelintels.user.MH.ImagePagerAdapter {
    private int[] mImages = new int[] {
            R.drawable.moet,
            R.drawable.hennessy,
            R.drawable.veuve,
            R.drawable.belvedere
    };

    @Override
    public int getCount() {
        return mImages.length;
    }
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Context context = MainActivity.this;
        ImageView imageSwipe = new ImageView(context);

        imageSwipe.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageSwipe.setImageResource(mImages[position]);
        container.addView(imageSwipe, 0);
        return imageSwipe;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object){

        container.removeView((ImageView) object);
    }
}

switch (id) { // menu item where I need to swipe images
        case R.id.belvedere_winery:
            dullBackground(); // clears other imageViews
            swipeWines(); // Not swiping images!
    }


public void dullBackground() { // clears the background before displaying new content
    AlphaAnimation alpha = new AlphaAnimation(0F, 0F);
    alpha.setDuration(0); // Make animation instant
    alpha.setFillAfter(true); // Tell it to persist after the animation ends
    try {
        imageSlideView.startAnimation(alpha);
        textSlideView.startAnimation(alpha);
    } catch (NullPointerException exe) {
        exe.printStackTrace();
    }
}`