2012-01-27 133 views
1

这里是一个android编程问题。 我遵循the offical example并编写一个由两个片段组成的活动,这两个片段显示一个列表菜单和内容。 当用户点击列表中的一个项目时,细节将显示在内容片段中。 现在,我想在操作栏中添加一个刷新按钮。当用户点击它时,内容片段中的内容将被重新加载。刷新片段的内容

但我不知道如何获取正在运行的内容片段的引用并调用它来刷新。 (假设所有的内容片断已经实施的方法被称为刷新())

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 { 
     ... 
    }  

总之,片段和活动如何包含通信的片段?

回答

1

覆盖片段中的onOptionsItemSelected而不是活动,并在那里对刷新事件进行内部处理。