Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:37:35+00:00 2026-05-23T12:37:35+00:00

I add menu’s in my application dynamically depending on the values i get from

  • 0

I add menu’s in my application dynamically depending on the values i get from the back-end in the onPrepareOptionsMenu(Menu menu). Now i would want to decide the action that is to be performed for the menu added dynamically (as i do not know the action to be performed beforehand) depending on certain values that came associated with the menu from the back-end. How do i achieve this. Kindly provide me some ideas on this. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:37:36+00:00Added an answer on May 23, 2026 at 12:37 pm

    I found a way to achieve what i wanted. I put the values associated to the menu as a part of the MenuItems intent. In the onOptionsItemSelected(MenuItem item) i get the intent from the MenuItem retrieve the values from it and perform the action required. The code is as below:

     @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        ApplicationManager.getInstance().resetCounter();
        menu.removeGroup(1);
        Vector listOfMenuToBeAdded=Service.getInstance().getMenuList();
        Enumeration<com.data.Menu> menuEnumeration = listOfMenuToBeAdded.elements();
        while (menuEnumeration.hasMoreElements()) {
            com.data.Menu levelOptions = (com.pravaa.mobile.dashboard.data.Menu) menuEnumeration
                    .nextElement();
            MenuItem levelMenuItem = menu.add(1, 100, Menu.NONE,
                    levelOptions.getCaption());
            LevelOptionIntent levelOptionIntent = new LevelOptionIntent();
            levelOptionIntent.setAppCode(levelOptions.getAppCode());
            levelOptionIntent.setDashboardNumber(levelOptions.getNumber());
            levelOptionIntent.setUniqueRecordId(levelOptions
                        .getUniqueRecordId());
            levelOptionIntent.setLevelNumber(levelOptions.getLevelNo());    
            levelMenuItem.setIntent(levelOptionIntent);
        }
        return true;
    }
    

    Once a menu item is clicked on perform the action according to the values set in the intent.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
        case 100:
            LevelOptionIntent levelOptionIntent = (LevelOptionIntent) item
                    .getIntent();
            //Perform what you would want to based on the values set in the intent.
            if (levelOptionIntent.getAppCode().equals(A)) {
            // Start activity A
            }elseif (levelOptionIntent.getAppCode().equals(B)) {
            // Start activity B
            }else if (levelOptionIntent.getAppCode().equals(C)) {
            // Start activity C
            }
    
            break;
        }
        return true;
    }
    

    The LevelOptionsIntent class is as below:

    public class LevelOptionIntent extends Intent {
    private int dashboardNumber;
    private String appCode;
    private String uniqueRecordId;
    private int levelNumber;
    
    public LevelOptionIntent() {
        super();
        // TODO Auto-generated constructor stub
    }
    public int getDashboardNumber() {
        return dashboardNumber;
    }
    public void setDashboardNumber(int dashboardNumber) {
        this.dashboardNumber = dashboardNumber;
    }
    public String getAppCode() {
        return appCode;
    }
    public void setAppCode(String appCode) {
        this.appCode = appCode;
    }
    public String getUniqueRecordId() {
        return uniqueRecordId;
    }
    public void setUniqueRecordId(String uniqueRecordId) {
        this.uniqueRecordId = uniqueRecordId;
    }
    public int getLevelNumber() {
        return levelNumber;
    }
    public void setLevelNumber(int levelNumber) {
        this.levelNumber = levelNumber;
    }}
    

    I am not sure if this is the right way of doing it though.Can someone throw some light on this.

    Thanks in advance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WPF application with a menu. I need to add menu
I would like to add a custom context menu with line separators, but can't
I have a dialog application in which I want to have clickable menu items
i have a menu generated dynamically by taking title from database. i have set
I want to add my menu in eclipse through eclipse plug-in development but not
I am using JxTaskPane to add menu items ..but i don't want to use
I'd like to add a menu item to the default ContextMenu of a RichTextBox
I am trying to add a new menu item to Eclipse's popupmenus. It really
I'm trying to add a navigational menu for my project which uses the ASP.NET
We had the Power Commands for Visual Studio 2008 that add a context menu

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.