Retrieve menu items from menu resources for custom view - java

Hey I'm working on a custom view and I need to retrieve menu items from menu resources (e.g. menu.xml from res/menu) but I didn't found any way to do that. How can I get users menu items from resources?

Related

Create circular JPopupMenu using Swing

I want to create a JPopupMenu that has a few items on it. Instead of rectangular layout of menu I it to open in circular manner and when I click one of the items on menu if it has any sub menu item then it should as a wrapper circular menu again out of the main menu.
I tried but was unable to achieve the requirement.
For reference please see the attached images:
File. Edit and Format are the main menu items. Cut, Copy and Paste are sub-menu items for each.

Show menu item icons in actionbar while having navigation drawer

Been trying everything to show the menu item search (searchWidget) in the actionbar. I have a navigationdrawer, which doesn't hide the actionbar items at any time. But still the search item is always at the overflow, even when having a large screen device.
I have tried using always in the showAsAction in the menu item, and even putting the menu item as visible in the onPrepareOptionsMenu method, and calling it when the drawer opens and closes to see if something changed, and still nothing.
I won't post code now, just wondering if someone had the same problem. If necessary I will post code of course.
If you are using regular action bar menu items (API 13+) then you simply need to say -
android:showAsAction="always"
for that menu item in the menu resource.
However, if you are using the compat library - appcompat-v7 for action bar and menu items (API 7+) then you need your app's name as the namespace as -
yourapp:showAsAction="always"
and add the following to menu tag at the top with the android namespace as -
xmlns:yourapp="http://schemas.android.com/apk/res-auto"

Collapsible Menu in Android Fragment

Is it possible to have a collapsible menu in a fragment, say for example...
Drinks
Juice
Soda
Main Dish
Spaghetti Carbonara
Pizzas
What I want to achieve is that, when I click the main menu "Drinks", I will collapse to show the submenu items.
If the collapsible thing is not possible, is it possible to hide the main menu then show only the submenus under the chosen main menu item?
for eg.
When I click the "Drinks" on the main menu, I will re-populate (well I don't know what's it called) the fragment with the submenu items. Is this achievable?
I read something about Fragments that I could not put another fragment on top of another one. Is this true?
I believe you are looking for an ExpandableListView.

Load a different form layout on spinner selection

On opening the activity, the user chooses an option from a spinner. I have the spinner working and I can successfully read the onItemSelected listener from the spinner. However, after the user clicks the spinner, I'd like to load a different form layout below the spinner; based on their choice. Can I store the different layouts in the same XML file, and then just call them based on their ID?
You can use different layout on a layout.See how to Inflate Layout.See this link for android layout Inflate.In your main layout create two linearLayout.add your spinner in the first layout.And in the second layout add various layout according to your choice using LayoutInflater

How to Display Menu Icons after clicking the More item in Android

if I have an Options menu in Android that has more than 6 items, Android adds a More item that shows the other hidden items, AS text!
But I want the More button to display the extra items both in their text AND icon, how do I do that?
I think this is not possible, unless you code that by your self. And by "code" I mean you create a custom menu.

Categories