How to use EventBus in Adapter and Fragment?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to use EventBus in Adapter and Fragment?



In my application i want use EventBUs for manage my event and i want use this into Adapter and Fragment.
In my adapter i should call Event. when select one item i want call event.
For this i write below code in adapter :


EventBUs


Adapter


Fragment


adapter


adapter


viewHolder.avatarItemList_img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Update image
EventBus.getDefault().postSticky(new EventUpdateAvatar());
});



My Fragment codes:


@Override
public void onStart() {
EventBus.getDefault().register(this);
super.onStart();
}

@Override
public void onDestroy() {
//unregister event bus
EventBus.getDefault().unregister(this);
super.onDestroy();
}

@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onUpdate(EventUpdateAvatar updateAvatar) {
Log.e("EventLog", "Call");
}



But when click on item (into adapter) not call event in fragment!


adapter


fragment



How can i fix this bug?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.