当前位置:网站首页>Simple use of event bus
Simple use of event bus
2022-06-13 06:21:00 【Novice Xiaowang】
1. Import dependence
implementation 'org.greenrobot:eventbus:3.0.0'
2. Customize Event class
public class MyEvent {
String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public MyEvent(String message) {
this.message = message;
}
}
3. Registering and unsubscribing
// Registration events
EventBus.getDefault().register(MainActivity.this);
// Unregister event
EventBus.getDefault().unregister(MainActivity.this);
4. Define how to handle events
@Subscribe(threadMode = ThreadMode.MAIN)
public void handleEvent(MyEvent myEvent){
textView.setText(myEvent.getMessage());
}
5. Send events
EventBus.getDefault().post(new MyEvent(" Send custom events "));
边栏推荐
- IOError(Errors.E050.format(name=name))
- Turn to 2005
- Uni app disable native navigation bar
- Custom view
- Uni app provincial and urban linkage
- Uniapp hides the scroll bar of scroll view
- Wechat applet: click the event to obtain the current device information (basic)
- App performance test: (III) traffic monitoring
- 2021-11-04 implementation of binary search
- [one · data 𞓜 simple implementation of the leading two-way circular linked list]
猜你喜欢
【新手上路常见问答】一步一步理解程序设计
JVM基础
RN Metro packaging process and sentry code monitoring
《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
Huawei developer certification and deveco studio compiler Download
Failed to extract manifest from apk: processexception:%1 is not a valid Win32 Application.
Echart histogram: stacked histogram displays value
Not in the following list of legal domain names, wechat applet solution
楊輝三角形詳解
Wechat applet custom tabbar (session customer service) vant
随机推荐
Intelligent digital asset management helps enterprises win the post epidemic Era
Recyclerview has data flicker problem using databinding
Notifyitemchanged flash back
JS convert text to language for playback
Explication détaillée du triangle Yang hui
Adding classes dynamically in uni app
Detailed explanation of Yanghui triangle
[one · data 𞓜 simple implementation of the leading two-way circular linked list]
【新手上路常见问答】一步一步理解程序设计
Dynamic link library nesting example
Uni app dynamic setting title
Echart line chart: when multiple lines have the same name, the legend is still displayed
Basic knowledge of knowledge map
Printf function
USB debugging assistant 20181018 (v1.3)
【新手上路常见问答】关于技术管理
Echart rectangular tree diagram: simple implementation of rectangular tree diagram
Wechat applet (get location)
1+1>2,Share Creators可以帮助您实现
Echart折线图:当多条折线存在相同name,图例仍全部显示