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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:25:10+00:00 2026-05-23T19:25:10+00:00

I have a list view with custom adapter, with an Image Button and a

  • 0

I have a list view with custom adapter, with an Image Button and a Text View.

I want to open a context menu when a press is made on the Image Button, and open another context menu if i press the Text View.

How can I do this??

This is my onClickListener

lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (id == view.findViewById(R.id.label).getId()) //label press
            {
                TextView text = (TextView) view.findViewById(R.id.label);
                registerForContextMenu(text);
                openContextMenu(text);
            }
            else //imageButton press
            {
                ImageButton ib= (ImageButton) view.findViewById(R.id.image);
                registerForContextMenu(ib);
                openContextMenu(ib);
            }
         }
       });
  • 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-23T19:25:11+00:00Added an answer on May 23, 2026 at 7:25 pm

    Add OnCreateContextMenuListener to the view:

        text.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
                @Override
                public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
                    menu.setHeaderTitle("Text context menu");
                    menu.add(ContextMenu.NONE, MY_OPTION_CONTEXT_MENU, ContextMenu.NONE, "Some option");
                }
            });
    

    In your activity view:

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    
        switch(item.getItemId()) {
            case MY_OPTION_CONTEXT_MENU:
                TextView v = (TextView) info.targetView;
                // more code here
                return true;
        }
    
        return super.onContextItemSelected(item);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list view with custom array adapter. I want to get items click
I have a list view filled with data. I set up a context menu
I have implemented a custom list view which looks like the twitter timeline. adapter
I currently have a simple list view adapter that holds two rows of text.
I have list activity with custom array adapter and I can't to get context
I have used a custom array adapter to populate my list view.The problem i
I have a list view with an image view and text in a linear
I have created a custom Base Adapter class, to populate a list view with
I have a custom list adapter: class ResultsListAdapter extends ArrayAdapter<RecordItem> { in the overridden
I have one listview.which contain one image ,text and one button .i had creted

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.