简体   繁体   中英

android: menu item click event from fragment

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM