B
B
Bravis20182018-04-17 16:54:34
Java
Bravis2018, 2018-04-17 16:54:34

How to pass a value to a specific fragment through EventBus?

There is an activity of two fragments. Each fragment is a subscriber and receives data as an Integer. How to send an Integer from an activity to a specific fragment if both fragments have a common signature.
Fragment1-2

@Subscribe
    public void onEvent(Integer event){
        Log.d("eventbus", ""+event);
        Toast.makeText(getActivity(), "Получено число:" + event, Toast.LENGTH_SHORT).show();
    }

MainActivity
EventBus.getDefault().post(6);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmtm, 2018-04-26
@Dmtm

obviously to make a different signature?
just wrap the original fragment:
Fragment1 extends CommonFragment
and
Fragment2 extends CommonFragment
and pass the class with the parameter to whom in the event

B
Boris K., 2018-04-26
@kaftanati

It is possible to initialize the signature in the fragment through the fragment constructor during creation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question