Access view from Fragment A in Fragment B

后端 未结 1 421
别那么骄傲
别那么骄傲 2021-01-25 17:27

Im trying to access a Textview from Fragment A in Fragment B to change the text, im getting a null pointer. ive tried the following.

public void setText(String te

相关标签:
1条回答
  • 2021-01-25 18:02

    Your code examples are pointing to the View of the current Fragment! To properly access the other Fragment's View, use this:

    text = (TextView) [otherFragmentInstance].getView().findViewById(R.id.message_menu);
    text.setText("bla bla");
    
    0 讨论(0)
提交回复
热议问题