Android: Change text within ViewPager

后端 未结 2 1017
生来不讨喜
生来不讨喜 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:00

    Well I don't garantee that this works but I had a similar problem with ViewPager using compatibility pack that I solved using this:

    In your view at the instatiateItem function do a setTag with your resId:

    view.setTag(resId);
    

    Then when you need to change your "city" do:

    View baseLayout = myPager.findViewWithTag(R.layout.forecast);
    TextView city = (TextView) baseLayout.findViewById(R.id.city_id);
    

    Where R.id.city_id is the id of your TextView.

提交回复
热议问题