Reputation: 411
My MainActivity have 3 different ListFragment (each has their own java file) which I can navigate through swiping left and right. There is an EditText that I want to access on Action Bar. How can I access it from any of the ListFragment? ListFragment does not have onCreateOptionsMenu(Menu menu) so I am not sure how to implement those code (supposed to be used in MainActivity) to get the EditText from the ListFragment
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
final EditText editText = (EditText) MenuItemCompat.getActionView(menu.findItem(R.id.action_settings));
}
Upvotes: 1
Views: 199
Reputation: 157437
Fragment has onCreateOptionsMenu(Menu, MenuInflater):
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main_activity_actions, menu);
super.onCreateOptionsMenu(menu,inflater);
}
it will be called only if you call
setHasOptionsMenu(true);
From the documentation
Initialize the contents of the Activity's standard options menu. You should place your menu items in to menu.
Upvotes: 1