1

Here is an android programming question. I follow the offical example and write an activity that consist of two fragments which show a list menu and content. When user click a item in list, detail will be shown in content fragment. Now, I want to add a refresh button in Actionbar. When user click it, content in content fragment will be reloaded.

But I don't know how to get the reference of the running content fragment and call it to refresh. (Suppose all content fragments have already implemented a method called 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 { ... } 

In short, how the fragment and the activity contains the fragment to communicate?

1 Answer 1

1

Override onOptionsItemSelected in the fragment rather than the activity and react internally to the refresh event there.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.