标签:
public class MessageEvent { public int position; public MessageEvent(int position) { this.position = position; } }
//DetailFragment.java
@Override public void onStart() { super.onStart();; EventBus.getDefault().register(this); } @Override public void onStart() { super.onStart(); setNewsCategory(0); EventBus.getDefault().register(this); }
//DetailFragment.java
public void onEvent(MessageEvent event){ int index = event.positioin; // do something using index,比如刷新文章内容 }
//HeadLineFragment.java
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
EventBus.getDefault().post(new MessageEvent(position)); }
这样子,DetailFragment的onEvent方法就会被调用,含有position的MessageEvent也就被传了过去,随之DetailFragment根据拿到的position来刷新界面。
-keepclassmembers class ** { public void onEvent*(**); }
EventBus框架在Android多Pane(Fragment)中的应用
标签:
原文地址:http://www.cnblogs.com/soaringEveryday/p/4598179.html