Update textView in Fragment from Activity

后端 未结 2 522
萌比男神i
萌比男神i 2021-01-27 16:25

I have 3 TextView in Fragment..

In MainActivity I have method which generate 3 string every 10 seconds.

And now I want to update TextViews from activity, but I

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-27 16:59

    Set id's for the textviews in the xml file: android:id="@+id/myId Then do this:

    TextView textView = (TextView) findViewById(R.id.myId);
    textView.setText("updated text");
    

提交回复
热议问题