0
我正在使用Otto EventBus。我有一個RecyclerViewAdapter,當我使用Bus.post方法單擊項目時,問題是該片段,我有一個recylcer視圖不接受事件,所以我沒有任何反應,當項目被點擊時,我註冊總線在活動中替換碎片和活動成功接受事件,但片段 - 不,所以我可以註冊片段的偵聽事件或我應該使用回調?我可以通過片段接受巴士事件嗎?
BusProvider類:
public final class BusProvider {
private static final Bus BUS = new Bus();
public static Bus getInstance() {
return BUS;
}
private BusProvider(){}
}
ViewHolderOnClick代碼
public void onClick(View v) {
transfers.remove(getAdapterPosition());
notifyItemRemoved(getAdapterPosition());
BusProvider.getInstance().post(new OnButtonDeleteClickEvent(transfers.isEmpty(), id));
break;
}
片段訂閱方法
@Subscribe
public void onButtonDeleteClick(OnButtonDeleteClickEvent event) {
db.deleteTransfer(event.getId());
if (event.isListEmpty()) {
setVisibility(false);
}
CustomToast toast = new CustomToast(getActivity(), getString(R.string.successfully_deleted));
toast.show();
}
我使用的是正確的@Subscribe和事件時,工作活動中使用它,我