Android Set Text of TextView in Fragment that is in FragmentPagerAdapter

前端 未结 4 1689

This one is driving me nuts. Basically, I want to create a ViewPager and add a few Fragments to it. Then, all I want to do, it set a value in one of th

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 15:39

    How about to change this line

    TextView t = (TextView) getView().findViewById(R.id.someTextView);  //UPDATE
    

    to

    TextView t = (TextView) getActivity().findViewById(R.id.someTextView);  //UPDATE
    

    then you can try to update "t" with .setText("some_string") inside "SheetActivity".

提交回复
热议问题