I made an Android app that have a top menu from the navigation drawable with 2 items, that are two vectors images, one to make a filter and one to add something. Reading the codelabs i have to override the 2 methods onCreateOptionsMenu (that put the menu in the fragment) and onOptionsItemSelected that is the "action listener". I don't undertand how to perform my actions to each item, so one open the fragment to the filter and the other one to open the fragment to add something.
Can someone explain me how to do it? It is correct what i'm doing? i want different toolbar for each fragment, with costum buttons on each toolbar
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater){
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.ticket_menu, menu)
}
override fun onOptionsItemSelected(item: MenuItem) : Boolean{
//the action to make when an items is clicked
return true;
}
my menu xml
<menu //with xmls and attributes>
<item>
android:id="@+id/filter"
android:icon="@drawable/ic_filter"
android:title:"@string/filter_text"
android:showAsAction="ifRoom"/>
<item>
android:id="@+id/add"
android:icon="@drawable/ic_add"
android:title:"@string/add_text"
android:showAsAction="ifRoom"/>
</menu>
question from:
https://stackoverflow.com/questions/66064401/android-add-individual-menu-item-actionlistener 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…