Communication between Fragments in ViewPager

前端 未结 4 1045
天命终不由人
天命终不由人 2020-12-01 06:57

I\'m trying to do this: http://android-er.blogspot.com/2012/06/communication-between-fragments-in.html Except that I\'m using a FragmentStatePagerAdapter

I have an

4条回答
  •  一生所求
    2020-12-01 07:37

    I use Mr. Rodion's solution above. But in addition, Android Studio asked me to add @Subscribe annotation before onEvent method.

    Like this:

    @Subscribe
    public void onEvent(TextChangedEvent event) {
        textView.setText(event.newText);
    }
    

    According to EventBus’ API:

    Subscribers implement event handling methods (also called “subscriber methods”) that will be called when an event is posted. These are defined with the @Subscribe annotation. Please note that with EventBus 3 the method name can be chosen freely (no naming conventions like in EventBus 2).

提交回复
热议问题