in Education by
I have created different fragment and populated some menu based on the fragment. I was getting duplicate menu items so I used clear as suggested various stackoveflow posts but the problem is when I use clear in fragment it also clears the main activity menu items. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Activity and all fragments inside it use the same Menu instance. So no matter where you call clear() method, all items will be deleted. Menu items that are used across all child fragments should be created inside Activity. Fragment-specific options should be created inside corresponding fragment. Ideally you should not have duplicated menu items. If two fragments have same menu item but third doesn't -- prefer create menu item inside every fragment but not single menu item inside activity. With this approach you will not get duplicates. But If you want just to delete duplicates you can use menu.removeItem(itemId) method. Also you can hide redundant item with menuItem.setVisible(false).

Related questions

0 votes
    I have a main activity which contains the action bar with 3 menu buttons in it. I then have a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Tested for Bash 5.0.2 According to the GNU Bash Reference Manual, Bash performs the expansion [of a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Tested for Bash 5.0.2 According to the GNU Bash Reference Manual, Bash performs the expansion [of a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have an experiment where I need to subtract values of two different treatments from the Control (baseline), but these ... , named block and year sampled. Dummy data frame: df...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I have an experiment where I need to subtract values of two different treatments from the Control (baseline), but these ... , named block and year sampled. Dummy data frame: df...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm experiencing some problems regarding Twitter OAuth within an android activity. I read a lot of tutorials ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I am creating an application for Android. I am using Realm as a Database. Realm working fine in the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have an activity A that launches B with an Intent. (B is a MapActivity and has some async code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    What is an activity in Android?...
asked Aug 13, 2021 in Technology by JackTerrance
0 votes
    How to launch an activity in android?...
asked Jan 14, 2021 in Technology by JackTerrance
...