How to write button onClick method in viewpager?

前端 未结 1 1559
孤街浪徒
孤街浪徒 2021-01-03 02:08

I want to Toast a message on button click using viewpager also I want more information on how to access views in viewpager.

I have tried following code.... not worki

相关标签:
1条回答
  • 2021-01-03 02:57

    Leave your code all the same but change:

        ((ViewPager) collection).addView(view, 0);
    
        return view;
    

    to

        ((ViewPager) collection).addView(v, 0);
    
        return v;
    

    you did the onclick right on a button that was inflated, then you inflated another view iwth resId and rendered it on the screen, that button exists in the memory of your app but no where else, by returning v, that button is drawn and the onclicklistener is invoked on click.

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