Reputation: 77
I have an application with actionbar. And there is menu inflated by the mainactivity. I want to intercept the click event inside the fragment but I don't know how? Can you help me please? MainActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.home, menu);
}
home.xml
<menu>
<item
android:id="@+id/action_refresh"
android:title="@string/menu_refresh"/>
</menu>
And I want to refresh the list in the fragment
Upvotes: 3
Views: 8316
Reputation: 1897
If you want to capture the click on your item, implement
public boolean onOptionsItemSelected(MenuItem item)
And then:
If your activity includes fragments, the system first calls onOptionsItemSelected() for the activity then for each fragment (in the order each fragment was added) until one returns true or all fragments have been called.
You can follow the oficial reference:
http://developer.android.com/guide/topics/ui/menus.html
Upvotes: 12