Android: Change text within ViewPager

后端 未结 2 1015
生来不讨喜
生来不讨喜 2021-02-11 05:30

Background

I\'m writing an app that uses the ViewPager and that\'s working nicely. I need to be able to target one of the layouts (xml file) and update

2条回答
  •  无人及你
    2021-02-11 06:08

    As a small addition to the above suggestion:

    1. When the tag was a String, for some weird reason it never assigned the tag to the View and it always returned null for findViewWithTag. Using the layout id worked though.

    2. Make sure you retrieve the views outside the onCreate(), preferably in the method where u intend to change the text for the text views. Trying to access them in onCreate returns null. My previous understanding was that, as soon as you call the MyPageAdapter, it will call the instantiateItem and so one should be able to find the views soon after that. But that isnt the case.

    I just burned a whole day the above 2 issues, since it wasnt really mentioned anywhere. Hope it helps people in the future.

提交回复
热议问题