作者:程序員小冰,GitHub主頁:https://github.com/QQ986945193
新浪微博:http://weibo.com/mcxiaobing
首先說明,以前我用eventBus的jar包寫得項目demo,前幾天就寫了一個EventBus的實例,這次我沒用jar包,直接用gradle引用的,可是demo寫完了,報錯:
its super classes have no public methods with the @Subscribe annotation
所以就用google搜索了一下,找到了解決方法,那就是在接受者
onEvent()方法添加註解: @Subscribe 然後問題解決,如:
/**
*
* 從發佈者那裏得到eventbus傳送過來的數據
*
* 加上@Subscribe以防報錯:its super classes have no public methods with the @Subscribe annotation
*
* @param event
*/
@Subscribe
public void onEvent(String event){
tv.setText(event);
}
效果圖如下:
eventBus簡單使用實例demo需要的可以直接去下載:
(AndroidStudio版)github下載地址:
https://github.com/QQ986945193/DavidEventBusDemo
(AndroidStudio版)git開源中國下載地址:
http://git.oschina.net/MCXIAOBING/DavidEventBusDemo
(AndroidStudio版)CSDN免積分下載地址:
http://download.csdn.net/detail/qq_21376985/9623446