ViewPager点击事件

 1. 关键代码 :pageClickListener.onItemClick(viewPager.getCurrentItem());
for (int i = 0; i < images.size(); i++) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.banner_item_layout, viewPager, false);
            ImageView imageView = (ImageView) view.findViewById(R.id.iv_banner_item);
            imageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (pageClickListener != null){
                        pageClickListener.onItemClick(viewPager.getCurrentItem());
                    }
                }
            });

2.调用

  mBanner.setPageClickListener(position -> {
            Intent intent = new Intent(getActivity(), BannerInfoActivity.class);
            intent.putExtra("aid", bannerListEntities.get(position).getId());
            startActivity(intent);
        });


你可能感兴趣的:(ViewPager点击事件)