Access view from Fragment A in Fragment B

后端 未结 1 422
别那么骄傲
别那么骄傲 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)
提交回复
热议问题