How to set OnClickListener in ViewPager

后端 未结 3 841
南笙
南笙 2021-01-01 07:45

I\'m new to Android development and I\'m studying to code & design an Android project. I have problem with ViewPager and can\'t find answer on this site or

相关标签:
3条回答
  • 2021-01-01 08:10
    viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int Position) {
                position=Position;
            }
     });
    

    You will use any view for clicking without viewpager and go to details by using the selected position of viewpager

    0 讨论(0)
  • 2021-01-01 08:13

    i found something tricky solution for the view pager.As view pager is dont have any click event you can try click events on the child of the view pager.What i mean is to set the on Click listener on each page's root element.That will work surely.

    0 讨论(0)
  • 2021-01-01 08:16

    Here is an easy solution.
    In your layout XML, in the button tag, set android:onClick="AnyName", then on your PagerDemo.java, place:

    public void AnyName(View v) {
        // Do your stuff
    }
    

    That sets onClickListener in a ViewPager.

    0 讨论(0)
提交回复
热议问题