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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:55:13+00:00 2026-05-30T12:55:13+00:00

How can I set title of the context menu from the selected Listview item?

  • 0

How can I set title of the context menu from the selected Listview item? This below is my main activity.

public class OListActivity extends ListActivity {
......
......
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        registerForContextMenu(getListView());
        ......
......
        MatrixCursor cursor;
        cursor = NameManager.getnameList();
        startManagingCursor(cursor);
        String[] from = { "name", "info", "status", BaseColumns._ID };
        int[] to = { R.id.name, R.id.info, R.id.status };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.row, cursor, from, to);
        setListAdapter(adapter);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("Menu");// TODO Change to name of selected listview item.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.context_menu, menu);
    }
.....
.....

I need to set menu.setHeaderTitle to R.id.name. I’m aware of another similer question but it don’t mention about dealing with a complex ListView with multiple textviews.

  • 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-30T12:55:15+00:00Added an answer on May 30, 2026 at 12:55 pm

    Use the ContextMenuInfo parameter from the onCreateContextMenu() method:

    @Override
        public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo) {
            super.onCreateContextMenu(menu, v, menuInfo);
            AdapterView.AdapterContextMenuInfo info;
            try {
                // Casts the incoming data object into the type for AdapterView objects.
                info = (AdapterView.AdapterContextMenuInfo) menuInfo;
            } catch (ClassCastException e) {
                // If the menu object can't be cast, logs an error.
                Log.e(TAG, "bad menuInfo", e);
                return;
            }
            Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
            if (cursor == null) {
                // For some reason the requested item isn't available, do nothing
                return;
            }
    
            // if your column name is "name"
            menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex("name")));
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.context_menu, menu);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we set Title for a Menu Item in Android if it has an
i can't set title to Action bar sherlock. Here is my code: public void
if($title =~ s/(\s|^|,|\/|;|\|)$replace(\s|$|,|\/|;|\|)//ig) $title can be a set of titles ranging from President, MD,
I create a context menu like this: @Override public void onCreateContextMenu(ContextMenu menu, View v,
How can I set the Title for a UINavigation Bar programmatically?
As title, how can I set a table's column to have the default value
I can set the event on the calendar on my device by using this
Someone can explain this error? Error Creating Control - head Object reference not set
As the title says, I have an UncaughtExceptionHandler set in my custom application class
I have two models: public class ProfessorModels { public string FullName { get; set;

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.