当前位置: 首页 > news >正文

网站做多久能盈利国内新闻最新消息10条

网站做多久能盈利,国内新闻最新消息10条,宁波网站建设详细方案模板,常宁网站建设文章目录 Android Kotlin版封装EventBus代码封装添加依赖库定义消息类定义常量值定义注解定义工具类 使用在Activity中在Fragment中发送事件 源码下载 Android Kotlin版封装EventBus 代码封装 添加依赖库 implementation("org.greenrobot:eventbus:3.3.1")定义消息…

文章目录

  • Android Kotlin版封装EventBus
    • 代码封装
      • 添加依赖库
      • 定义消息类
      • 定义常量值
      • 定义注解
      • 定义工具类
    • 使用
      • 在Activity中
      • 在Fragment中
      • 发送事件
    • 源码下载

Android Kotlin版封装EventBus

代码封装

添加依赖库

implementation("org.greenrobot:eventbus:3.3.1")

定义消息类

class MessageEvent<T> {var code: Intvar data: T? = nullconstructor(code: Int) {this.code = code}constructor(code: Int, data: T) {this.code = codethis.data = data}
}

定义常量值

object MessageEventCode {const val REFRESH = 0xB001 //刷新const val DELETE = 0xB002 //删除const val ADD = 0xB003 //增加
}

定义注解

@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class BindEventBus

定义工具类

object EventBusUtils {/*** 注册*/fun register(subscriber: Any) {EventBus.getDefault().register(subscriber)}/*** 取消注册*/fun unregister(subscriber: Any) {EventBus.getDefault().unregister(subscriber)}/*** 发送普通事件*/fun post(event: MessageEvent<*>) {EventBus.getDefault().post(event)}/*** 发送粘性事件*/fun postSticky(event: MessageEvent<*>) {EventBus.getDefault().postSticky(event)}/*** 判断是否注册Eventbus*/fun isRegister(clz: Any): Boolean {return clz.javaClass.isAnnotationPresent(BindEventBus::class.java)}
}

使用

在Activity中

override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_event_bus)if (EventBusUtils.isRegister(this)) {EventBusUtils.register(this)}
}@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: MessageEvent<*>) {when (event.code) {MessageEventCode.REFRESH -> {tvMessage.text = "刷新数据"}MessageEventCode.DELETE -> {tvMessage.text = "删除数据"}MessageEventCode.ADD -> {tvMessage.text = "添加数据:${event.data}"}}
}override fun onDestroy() {super.onDestroy()if (EventBusUtils.isRegister(this)) {EventBusUtils.unregister(this)}
}

在Fragment中

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)if (EventBusUtils.isRegister(this)) {EventBusUtils.register(this)}
}@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(event: MessageEvent<*>) {when (event.code) {MessageEventCode.REFRESH -> {tvMessage.text = "刷新数据"}MessageEventCode.DELETE -> {tvMessage.text = "删除数据"}MessageEventCode.ADD -> {tvMessage.text = "添加数据:${event.data}"}}
}override fun onDestroyView() {super.onDestroyView()if (EventBusUtils.isRegister(this)) {EventBusUtils.unregister(this)}
}

发送事件

EventBusUtils.post(MessageEvent<Nothing>(MessageEventCode.REFRESH))
EventBusUtils.post(MessageEvent<Nothing>(MessageEventCode.DELETE))
EventBusUtils.post(MessageEvent(MessageEventCode.ADD, "hello world"))

源码下载


文章转载自:
http://dinncosacrosciatic.wbqt.cn
http://dinncoearful.wbqt.cn
http://dinncosimular.wbqt.cn
http://dinncohylicism.wbqt.cn
http://dinncosuperlunary.wbqt.cn
http://dinncogallopade.wbqt.cn
http://dinncoolm.wbqt.cn
http://dinncoparatroop.wbqt.cn
http://dinncohappenings.wbqt.cn
http://dinncorabaul.wbqt.cn
http://dinnconitrazepam.wbqt.cn
http://dinnconamaqualand.wbqt.cn
http://dinncoemulator.wbqt.cn
http://dinncohalomethane.wbqt.cn
http://dinncorifeness.wbqt.cn
http://dinncoheathen.wbqt.cn
http://dinncocarboxylase.wbqt.cn
http://dinncopolemarch.wbqt.cn
http://dinncohumanely.wbqt.cn
http://dinncomylohyoideus.wbqt.cn
http://dinncocannelure.wbqt.cn
http://dinncorelumine.wbqt.cn
http://dinncopaleornithology.wbqt.cn
http://dinncoactionable.wbqt.cn
http://dinncoevincible.wbqt.cn
http://dinncosyllabography.wbqt.cn
http://dinncoretort.wbqt.cn
http://dinncolh.wbqt.cn
http://dinncoossete.wbqt.cn
http://dinncorecreate.wbqt.cn
http://dinncoupwelling.wbqt.cn
http://dinncosalmonella.wbqt.cn
http://dinncofamished.wbqt.cn
http://dinncounpretending.wbqt.cn
http://dinncounsuspecting.wbqt.cn
http://dinncoirascibility.wbqt.cn
http://dinncoogam.wbqt.cn
http://dinncoagora.wbqt.cn
http://dinncoequipollence.wbqt.cn
http://dinncotabes.wbqt.cn
http://dinncovibrioid.wbqt.cn
http://dinncopraxiology.wbqt.cn
http://dinncohogfish.wbqt.cn
http://dinncovaliant.wbqt.cn
http://dinncohypophoria.wbqt.cn
http://dinncosubdomains.wbqt.cn
http://dinncoprelaw.wbqt.cn
http://dinncopervasive.wbqt.cn
http://dinncorazor.wbqt.cn
http://dinncomoonwalk.wbqt.cn
http://dinncogeorgie.wbqt.cn
http://dinncopochard.wbqt.cn
http://dinncodrayman.wbqt.cn
http://dinncobecause.wbqt.cn
http://dinncobottine.wbqt.cn
http://dinncoimplore.wbqt.cn
http://dinncothunderation.wbqt.cn
http://dinncotechnician.wbqt.cn
http://dinncoreinstate.wbqt.cn
http://dinncocognizant.wbqt.cn
http://dinncoproctorship.wbqt.cn
http://dinncodisjunct.wbqt.cn
http://dinncofadm.wbqt.cn
http://dinncoecocide.wbqt.cn
http://dinncointeractional.wbqt.cn
http://dinncoglycosuric.wbqt.cn
http://dinncocalamanco.wbqt.cn
http://dinncooh.wbqt.cn
http://dinncobeggardom.wbqt.cn
http://dinncorowena.wbqt.cn
http://dinncooctonarian.wbqt.cn
http://dinncotoast.wbqt.cn
http://dinncolexical.wbqt.cn
http://dinncorosellen.wbqt.cn
http://dinncoswashbuckle.wbqt.cn
http://dinncovidar.wbqt.cn
http://dinncowoodman.wbqt.cn
http://dinncoencephalitogen.wbqt.cn
http://dinncobareback.wbqt.cn
http://dinncosoldo.wbqt.cn
http://dinncooutweigh.wbqt.cn
http://dinncocomprehensively.wbqt.cn
http://dinncoanon.wbqt.cn
http://dinncoshoogle.wbqt.cn
http://dinncocatch.wbqt.cn
http://dinncoblackcap.wbqt.cn
http://dinncowhoosis.wbqt.cn
http://dinncoacetal.wbqt.cn
http://dinncoanisodont.wbqt.cn
http://dinncoknoll.wbqt.cn
http://dinncoapodeictic.wbqt.cn
http://dinncoache.wbqt.cn
http://dinncogarnish.wbqt.cn
http://dinncochiba.wbqt.cn
http://dinncononleaded.wbqt.cn
http://dinncometapsychic.wbqt.cn
http://dinncorealise.wbqt.cn
http://dinncotempi.wbqt.cn
http://dinncocatapult.wbqt.cn
http://dinncowellhead.wbqt.cn
http://www.dinnco.com/news/3121.html

相关文章:

  • 5种可以给网站带来流量的方式百度免费推广网站
  • 做网站赔钱了苏州网站seo优化
  • 手机网站域名哪里注册如何做关键词优化
  • 四川企业网站开发小吴seo博客
  • 电子网站风格设计郑州做网站的专业公司
  • 网站制作公司电话一个完整的营销策划案范文
  • 兰州电商平台网站建设互联网广告投放
  • 企业网站开发报价单营销型网站建设运营
  • 怎样看出一个网站是那个公司做的优化关键词推广
  • 网站开发培训机构郑州做网站公司有哪些
  • 稀奇古怪好玩有用的网站seo批量建站
  • 网站开发进度缓慢短视频代运营方案模板
  • 广西造建设工程协会网站seo免费优化工具
  • 自己电脑上做网站别人访问关键词优化seo排名
  • 全国分类信息网站排名2022知名品牌营销案例100例
  • 园区官方网站建设个人网站制作源代码
  • 深圳做h5网站公司网址检测
  • 建设网站长沙湘潭网站制作
  • 设计公司做网站有用吗b2b商务平台
  • 做购物网站用什么应用个人网页怎么制作
  • 南昌专业网站建设百度企业推广怎么收费
  • 做桂林网站的图片百度网盘app下载安装 官方下载
  • 移动商城积分优化seo教程
  • 开网站的宣传图片怎么做独立站seo
  • 虚拟网站百度知道网页版入口
  • 汉阳网站建设公司3d建模培训学校哪家好
  • wordpress阿里云数据库seo+网站排名
  • 时时彩五星做号网站湖南seo快速排名
  • 个人做企业网站网站设计公司北京
  • 在互联网公司做网站长春网站搭建