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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:30:16+00:00 2026-05-26T04:30:16+00:00

My app contains 1 list view, data source is 1 sqlite table, when i

  • 0

My app contains 1 list view, data source is 1 sqlite table, when i hold long click on any row in listview it will show me 1 menu option to change the color of that row, for this i have used onContextItemSelected function, on selecting menu option it will call 1 function change_color. What should i write in change_color function so that i can change row bg color.

    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.add(0, PROCESSED_ID, 0, R.string.menu_processed);
    }



    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case PROCESSED_ID:
            AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
                    .getMenuInfo();

            change_color();
            return true;
        }
        return super.onContextItemSelected(item);
    }
  • 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-26T04:30:17+00:00Added an answer on May 26, 2026 at 4:30 am

    Call your method as :

    change_color(pass_your_list_view, pass_selected_position_of_list_view);
    

    And define change_color() as:

    private void change_color(ListView listView, int position) {
        listView.getChildAt(position).setBackgroundColor(Color.BLACK);
    }
    

    Hope this will help.

    Edited

    Define a variable a position

    public static int position;
    

    And replace your code as

    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.add(0, PROCESSED_ID, 0, R.string.menu_processed);
    
        // Get the info on which item was selected
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        // Retrieve the position at where you long pressed
        position = info.position;
    
    }
    
    
    
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case PROCESSED_ID:
            AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
                    .getMenuInfo();
    
            change_color(getListView(), position);
            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 a long ListView which contains a list of actions which my app
My app is a Navigation based application. The main menu contains the list view
My Django app has a Person table, which contains the following text in a
I have a top list view in my current iPhone app, that's populated by
In my winforms app, I have a list view control that is populated with
I'm building an app that contains a listview that is populated from a database
I'm using a list view in my app and which grows dynamically. Initially list
In my cocoa app there is a NSTableView(10.7 lion view based tableview) only contains
In my app I'm using base adapter to display continents on list view.I want
This is a toy project I'm working on at the moment. My app contains

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.