Android: event event of menu item from fragment

I have an application with an action bar. And there is a menu inflated by core activity. I want to intercept the click event inside a fragment, but I don't know how? could you help me? 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 update the list in a fragment

+3


source to share


1 answer


If you want to grab a click on an element, do

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 in which each fragment is added) until true is returned or all fragments have been called.

You can follow the official link:

http://developer.android.com/guide/topics/ui/menus.html

+7


source







All Articles