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 8397703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:51:46+00:00 2026-06-09T20:51:46+00:00

How do I change the text of my pop up context menu items? I

  • 0

How do I change the text of my pop up context menu items? I want the context menu to have a header, and I want to set it based on the underlying content. The context menu pops up find with static strings, but I want to change the titles dynamically. I can’t seem to get a handle on the MenuItem objects!

Main.java:70: error: int cannot be dereferenced
[javac]             MenuItem mi = R.menu.context_menu.articleTitle;
                                                      ^

Here is the code to bring up the context menu:

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
    Article a = display.getArticle();
    MenuItem mi = R.menu.context_menu.articleTitle;
    mi.setTitle(a.getTitle());
    mi = R.id.articleURL; // this doesn't work either
    mi.setTitle(a.url);
}

I also tried

    MenuItem mi = (MenuItem) findViewById(R.id.articleTitle);
    mi.setTitle(a.getTitle());

But it gave me a NullPointerException. Here is the menu resource:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/contextHeader"
       android:enabled="false"
>
    <item android:id="@+id/articleTitle"
        android:title="Title"
    />
    <item android:id="@+id/articleURL"
        android:title="URL"
    />
</group>
<item android:id="@+id/share"
      android:title="Share"
      android:icon="@android:drawable/ic_menu_share"
/>
<item android:id="@+id/skip"
    android:title="Skip"
    android:icon="@android:drawable/ic_media_next"
/>
</menu>
  • 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-06-09T20:51:48+00:00Added an answer on June 9, 2026 at 8:51 pm

    If you want to change the title of your context menu, use the setHeaderTitle() on your menu instance.
    To change the text (title) of a menuitem programatically, use the menu.findItem(R.id.menu_item_id_defined_in_your_XML). After that, you can change this MenuItem’s attributes, like title, icon, showAsAction, etc.

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.context_menu, menu);
        //Set a title for the context menu
        menu.setHeaderTitle("Title of menu");
    
        // Select a menu item then change it's title (text)
        MenuItem mi = (MenuItem) menu.findItem(R.id.new_game);
        mi.setTitle("Text of item");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change text of custom UITableviewCell text on didSelectRowAtIndexPath and I am
I want to change the text from User Account to something else when users
I have this application where the users can change text files and when they
Hello I am trying to change the text color of the items in a
I want to change the opacity of an object instead of fading in content
I register for notification NSPopUpButtonWillPopUpNotification in order to change the pop up menu before
I'm try to change text color and align item in spinner to center of
I'm curious is it possible to change text properties of tick labels independently of
I found this code posted on SO to change text links into hyperlinks: function
I am generating user control according to search result. And allowing to change text

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.