Fragment之间通过EventBus相互传值或调用方法

来源:互联网 发布:互联网数据分析师 编辑:程序博客网 时间:2024/05/21 07:07

1。event 总类

package com.louisgeek.louisdemo;/** * Created by louisgeek on 2016/4/3. */public class EventAll {      class  EventLoadData{        private int pos;        public EventLoadData(int pos) {            this.pos = pos;        }        public int getPos() {            return pos;        }    }        //other event class     class  EventAddData{        private int pos;        public EventAddData(int pos) {            this.pos = pos;        }        public int getPos() {            return pos;        }    }}

2。

     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {            @Override            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {                //内部类 new A().new B();                EventBus.getDefault().post(new EventAll().new EventLoadData(position));            }        });

3。刷新数据

   @Subscribe(threadMode = ThreadMode.MAIN)    public void onEveMain(EventAll.EventLoadData eventLoadData)    {        int pos=eventLoadData.getPos();       // onLoad(pos);    }

这里写图片描述

demo下载:http://download.csdn.net/detail/richiezhu/9480372

0 0
原创粉丝点击