当前位置:网站首页>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 "));边栏推荐
- Echart line chart: different colors are displayed when the names of multiple line charts are the same
- Custom view
- Super model logo online design and production tool
- 《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
- 无刷直流电机矢量控制(四):基于滑模观测器的无传感器控制
- How to view APK version number from apk
- Uni app disable native navigation bar
- [case] a super easy-to-use tool -- a calculator for programmers
- The Boys x PUBGMOBILE 联动火热来袭!来看最新游戏海报
- A brief analysis of the overall process of view drawing
猜你喜欢
随机推荐
《MATLAB 神经网络43个案例分析》:第10章 离散Hopfield神经网络的分类——高校科研能力评价
JS convert text to language for playback
Echart折线图:多条折线图每次仅展示一条
synchronized浅析
Uniapp mobile terminal uses canvas to draw background convex arc
Turn to 2005
Learning records countless questions (JS)
Echart histogram: stacked histogram displays value
pthon 执行 pip 指令报错 You should consider upgrading via ...
Uni app disable native navigation bar
USB debugging assistant (20191028)
Add attributes in storyboard and Xib (fillet, foreground...) Ibinspectable and ibdesignable
Wechat applet: basic review
USB status error and its cause (error code)
Custom view - extensible collapsexpendview
IOError(Errors.E050.format(name=name))
A glimpse of [wechat applet]
Local file search tool everything
Printf function
Echart histogram: echart implements stacked histogram








