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

  • SEARCH
  • Home
  • 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 6919973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:05:22+00:00 2026-05-27T10:05:22+00:00

I have a contextMenu set up and it shows items from the list. However,

  • 0

I have a contextMenu set up and it shows items from the list. However, when item selected, it doesn’t do anything. I have tried various ways; using .setCheckable() or invoking intent. I am not receving any errors, but it isn’t doing anything. The same class can be invoked via Intent from a separate button and it works fine.

I think I am missing some vital detail in the code.

    `package com.myExperiment.androidapp.userinterface;

import android.app.Activity;
//import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
//import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
//import android.view.ViewGroup;
import android.widget.Button;
//import android.widget.ListView;
//import android.widget.Toast;


public class MyHome extends Activity 
{

    Button btnMyMenu;
    Button btnAnnouncements;
    Button btnGoToWebsite;
    Button btnWorkflows;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homelayout);

        //Initialising variables with xml properties
        btnMyMenu = (Button) findViewById(R.id.buttonMyStuff);
        btnAnnouncements = (Button) findViewById(R.id.buttonAnnouncements);
        btnGoToWebsite = (Button) findViewById(R.id.buttonWebsite);
        btnWorkflows = (Button)findViewById(R.id.buttonWorkflow);

        //Checking for button click listeners
        btnMyMenu.setOnClickListener(actionOnClickListener);
        btnGoToWebsite.setOnClickListener(buttonGoToWebsite);
        btnWorkflows.setOnClickListener(buttonWorkflows);

        //checking for context menu cluck
        registerForContextMenu(btnMyMenu);

    }//onCreate


    View.OnClickListener buttonWorkflows = new View.OnClickListener() 
    {

        @Override
        public void onClick(View v) 
        {
            Intent workflowIntent = new Intent(MyHome.this, Workflows.class);
            startActivity(workflowIntent);
        }
    };


    //Open myExperiment website when button clicked
    View.OnClickListener buttonGoToWebsite = new View.OnClickListener() 
    {

        @Override
        public void onClick(View v) 
        {
            String website = "http://www.myexperiment.org";
            Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(website));
            startActivity(browse);
        }
    };



    private View.OnClickListener actionOnClickListener = new View.OnClickListener() 
    {

        @Override
        public void onClick(View v) 
        {
            if (v != null)
            {
                v.showContextMenu();
            }

        }
    };


    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
    {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("My Menu");
        menu.add(0, v.getId(), 0, "Workflows");
        menu.add(0, v.getId(), 0, "Credits");
        menu.add(0, v.getId(), 0, "Friends");
        menu.add(0, v.getId(), 0, "Groups");
        menu.add(0, v.getId(), 0, "Notifications");

    }//onCreateContextMenu

    public boolean onCreateItemSelected(MenuItem item)
    {
        if(item.getTitle() == "Workflows")
        {
            Intent workflowIntent = (Intent) item.setIntent(new Intent(MyHome.this, Workflows.class));
            startActivity(workflowIntent);


        }
        else if(item.getTitle() == "Credits")
        {


                    Intent creditsIntent = new Intent(MyHome.this, Credits.class);
                    startActivity(creditsIntent);

        }
        else if(item.getTitle() == "Friends")
        {

            View.OnClickListener buttonFriendsHandler = new View.OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {
                    Intent friendsIntent = new Intent(MyHome.this, Friends.class);
                    startActivity(friendsIntent);

                }
            };

        }


        else 
        { 
            return false; 
        }


        return true;    

    }//onCreateItemSelected


}
  • 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-27T10:05:23+00:00Added an answer on May 27, 2026 at 10:05 am

    Your title matching isn’t working. Change it to item.getTitle().equals("Workflows") etc.

    Even better, use id matching instead of string matching. Add your menu items this way:

    int groupId = v.getId();
    menu.add(groupId, 0, ContextMenu.NONE, "Workflows");
    menu.add(groupId, 1, ContextMenu.NONE, "Credits");  // etc
    

    Also, you don’t need to set the intent of the menu item. So, in onCreateItemSelected:

    public boolean onCreateItemSelected(MenuItem item) {
      switch(item.getItemId()) {
        case 0:
          Intent workflowIntent = new Intent(this, Workflows.class);
          startActivity(workflowIntent);
          break;
        case 1:
          Intent creditsIntent = new Intent(MyHome.this, Credits.class);
          startActivity(creditsIntent);
          break;
        // etc
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SubMenu in a ContextMenu which ItemSource is set to a expression
I have a list view filled with data. I set up a context menu
Inside my control, I have: ContextMenu = new ContextMenu(); ContextMenu.MenuItems.Add(new MenuItem(&Add Item, onAddSpeaker)); ContextMenu.MenuItems.Add(new
I have a tricky problem where I am binding a ContextMenu to a set
I have a ContextMenu that is displayed after a user right clicks on a
I have created a custom style and template for MenuItem and ContextMenu, and for
I have a DataTemplate containing an Image. To the Image I added a ContextMenu
I want to set the CommandTarget of the MenuItem of ContextMenu, in a Style,
I have a ListView with custom adapter which is populated from local sqlite database.
I'm trying to make a list of items that you can do several actions

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.