HeaderViewPager icon indicating copy to clipboard operation
HeaderViewPager copied to clipboard

LoopviewPager click listener not working

Open arunrajgm opened this issue 8 years ago • 8 comments

Hi guys, now only i seen this library.its awesome. But here in loop viewpager.i click on the image but its didn't trigger a click event. i tried all ways.but no luck Can u plz help me Thanks.

arunrajgm avatar Nov 17 '16 07:11 arunrajgm

you should add onClickLiatener in HeaderAdapter ,such as:

private class HeaderAdapter extends PagerAdapter {

    public int[] images = new int[]{//
                                    R.mipmap.image1, R.mipmap.image2, R.mipmap.image3,//
                                    R.mipmap.image4, R.mipmap.image5};

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView imageView = new ImageView(getApplicationContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(images[position]);
        container.addView(imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "第" + position + "页", Toast.LENGTH_SHORT).show();
            }
        });
        return imageView;
    }

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

    @Override
    public int getCount() {
        return images.length;
    }

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

jeasonlzy avatar Nov 17 '16 13:11 jeasonlzy

hi jeasonlzy, I already tried this. But its not working. Any other way is there?

arunrajgm avatar Nov 17 '16 16:11 arunrajgm

you can download or clone the latest code and try again, I have already added click event in demo。

jeasonlzy avatar Nov 18 '16 02:11 jeasonlzy

Finally i got it.its works Thank you very much for your quick response jeasonlzy..

arunrajgm avatar Nov 18 '16 06:11 arunrajgm

But 1 small issue is there. after scrolldown the loopviewpager hided.But i click on the actionbar,the loopview pager click listener is triggerd.its wrong right

arunrajgm avatar Nov 18 '16 06:11 arunrajgm

1111

you can solve this issue by only one line of code,just make the action bar consume the click event。

jeasonlzy avatar Nov 18 '16 06:11 jeasonlzy

Super.its solved. In recyclerview your are using simple textview. But in recyclerview with custom layout the loopviewpager not opening again when scroll top again .

arunrajgm avatar Nov 18 '16 07:11 arunrajgm

i am facing issues on firebase recycler adater in your library..

arunrajgm avatar Nov 18 '16 08:11 arunrajgm