public class fragment1 extends Fragment
{
private View rootView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.fragment1_layout, container, false);
Button sendMessage = (Button)rootView.findViewById(R.id.send_btn);
sendMessage.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
EventBus.getDefault().post(new SomeEvent("Hello this is Fragment1!!"));
}
});
return rootView;
}
}
> fragment2.java
```java
public class fragment2 extends Fragment
{
private View rootView;
private TextView receiveString;
private String tmpString;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.fragment2_layout, container, false);
receiveString = (TextView)rootView.findViewById(R.id.textView2);
return rootView;
}
@Subscribe(threadMode = ThreadMode.MainThread)
public void onEven(SomeEvent event)
{
tmpString += event.getMessage() + "\n";
receiveString.setText(tmpString);
}
@Override
public void onStart()
{
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop()
{
super.onStop();
EventBus.getDefault().unregister(this);
}
}