日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android_Event Bus 的基本用法

發(fā)布時(shí)間:2023/11/30 Android 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android_Event Bus 的基本用法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

?

?

1 //事件總線分發(fā) 2 public class MainActivity extends ActionBarActivity { 3 Button button; 4 TextView text; 5 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.fragment_main); 10 11 button = (Button) findViewById(R.id.button1); 12 text = (TextView) findViewById(R.id.textView1); 13 EventBus.getDefault().register(this);// 注冊(cè) 14 button.setOnClickListener(new OnClickListener() { 15 // 發(fā)送事件 16 @Override 17 public void onClick(View v) { 18 MyEvent my=new MyEvent(); 19 my.setType("0"); 20 my.setContent("0內(nèi)容"); 21 EventBus.getDefault().post(my); 22 } 23 }); 24 } 25 26 27 28 // 接收數(shù)據(jù)消息事件 29 // public void onEvent(MyEvent event) { 30 // if (event.getType().equals("0")) { 31 // text.setText(event.getContent()); 32 // } 33 // 34 // } 35 36 public void onEventMainThread(MyEvent event) { 37 if (event.getType().equals("0")) { 38 text.setText(event.getContent()); 39 } 40 } 41 // 42 // public void onEventPostThread(String string) { 43 // 44 // } 45 // 46 // public void onEventBackgroundThread(String string) { 47 // 48 // } 49 // 50 // public void onEventAsync(String string) { 51 // 52 // } 53 54 @Override 55 protected void onDestroy() { 56 // TODO Auto-generated method stub 57 super.onDestroy(); 58 EventBus.getDefault().unregister(this);// 取消注冊(cè) 59 } 60 61 }

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/my334420/p/7074130.html

總結(jié)

以上是生活随笔為你收集整理的Android_Event Bus 的基本用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。