【发布时间】:2012-01-27 08:03:49
【问题描述】:
这是一个 android 编程问题。 我关注the offical example 并编写了一个活动,该活动由两个显示列表菜单和内容的片段组成。 当用户单击列表中的项目时,详细信息将显示在内容片段中。 现在,我想在 Actionbar 中添加一个刷新按钮。当用户点击它时,内容片段中的内容将被重新加载。
但是我不知道如何获取正在运行的内容片段的引用并调用它进行刷新。 (假设所有内容片段都已经实现了一个名为 refresh() 的方法)
public class FragmentLayout extends Activity {
.....
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_reload: //refresh button is clicked
//how can I call the DetailFragment to reload here?
}
public static class TitlesFragment extends ListFragment {
....
}
public static class DetailFragment extends Fragment {
...
}
简而言之,fragment和activity包含的fragment如何通信?
【问题讨论】:
标签: java android android-fragments