2012-01-27 134 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而不是活動,並在那裏對刷新事件進行內部處理。