I am trying to access menu item so that I can apply click event but I am unable to do this because I have use given code for display and click menu item i have one activity inside there is fragment i have to access menu item in fragment and there i have apply click function on menu but i don't know why this not coming please suggest me what wrong with given code
Menuitem.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_advance_search_query"
android:enabled="false"
android:title="@string/label_search"
app:showAsAction="always" />
</menu>
Activity Call
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.action_advance_search_query -> {
// if (mListener != null) {
// mListener?.onAdvanceSearchQuery()
// }
}
}
return false
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val inflater:MenuInflater = menuInflater
inflater.inflate(R.menu.menu_cs_search_advance, menu);
return true;
}
Fragment Call:
onCreatView{
setHasOptionsMenu(true)
}
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
inflater?.inflate(R.menu.menu_cs_search_advance, menu)
this.menu = menu
super.onCreateOptionsMenu(menu, inflater)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.action_advance_search_query -> {
if (mListener != null) {
mListener?.onAdvanceSearchQuery()
}
}
}
return false
}