Reputation: 416
snapshot
[1]: https://i.sstatic.net/P0uHw.png
please help how to show overflow menu in fragment.my code below
this is my fragment code:.,,.,.,.,.,.,.,
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_main, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
this is my menu 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"
xmlns:myapp="http://schemas.android.com/tools"
>
<item
android:id="@+id/addContactItemId"
android:title="@string/addContact"
android:orderInCategory="101"
myapp:showAsAction="ifRoom|withText"
/>
please help me.thanks in advance.i have saw some tutorial where overflow menu created by default but it was for activity but i am trying overflow menu in fragment.please help
Upvotes: 0
Views: 123
Reputation: 3118
Do you have setHasOptionsMenu(true) in your code somewhere for this particular fragment you want the menu in?
Something like...
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
Your fragment must be told that it has an options menu otherwise it won't try to inflate one.
Documentation: setHasOptionsMenu(boolean hasMenu)
Upvotes: 1