android:菜单项单击事件从片段 [英] android: menu item click event from fragment
问题描述
我有一个带有动作栏的应用程序.并且还有因主要活动而膨胀的菜单.我想截取片段内的click事件,但是我不知道怎么办?你能帮我吗? MainActivity
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>
我想刷新片段中的列表
推荐答案
如果您想捕获项目的点击,请实施
If you want to capture the click on your item, implement
public boolean onOptionsItemSelected(MenuItem item)
然后:
如果您的活动中包含片段,则系统会先调用 活动的onOptionsItemSelected(),然后是每个片段(在 每个片段的添加顺序),直到一个返回true或全部 片段已被调用.
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.
您可以遵循官方参考:
http://developer.android.com/guide/topics/ui/menus.html
这篇关于android:菜单项单击事件从片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!