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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:58:17+00:00 2026-05-24T06:58:17+00:00

In Android, by default when you long click on a list item, it goes

  • 0

In Android, by default when you long click on a list item, it goes from the highlight color to white indicating that the user has held it down and a context item will be displayed. Also, you can use the trackball (or arrow buttons on some phones) to select list items rather then using your fingers.

However, I have a ListView whose item’s views I am calling setBackgroundColor on, and both of those expected behaviors no longer work. Anybody know why this is and how to fix it?

Notes: Setting the background color in the xml is not an option because I need to be able to set/change the color dynamically.

The code for my newView function is as follows:

@Override
public View newView(Context ctx, Cursor cursor, ViewGroup parent)
{
    View view = new View(mCtx);
    final LayoutInflater li = (LayoutInflater) mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = li.inflate(R.layout.task_list_item, null);

    return view;
}
  • 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-24T06:58:18+00:00Added an answer on May 24, 2026 at 6:58 am

    By default, ListView has a Selector that will play a TransitionDrawable when you longpress a list item. However, if your list item view has a solid background, then you won’t be able to see the selector’s longpress animation (or on any other states) , because it’s covered up by the list item’s background.

    If you want to see the selector’s longpress animation/selected/pressed state, then the list item’s has to have a transparent background when the item is selected/pressed/longpressed. You can do it by using a StateListDrawable as your item’s background instead of a solid color.

    Here is a sample of StateListDrawable for that purpose:

    public class ColorfulListItemDrawable extends StateListDrawable {
        private final PaintDrawable mColor;
    
        public ColorfulListItemDrawable(int color) {
            mColor = new PaintDrawable(color);
            initialize();
        }
        private void initialize() {
            Drawable color = mColor;
            Drawable selected = new ColorDrawable(Color.TRANSPARENT);
            addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled, 
                    android.R.attr.state_window_focused}, selected);
            addState(new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled, 
                    android.R.attr.state_window_focused,android.R.attr.state_selected}, selected);
            addState(new int[] {android.R.attr.state_enabled,android.R.attr.state_window_focused, android.R.attr.state_selected}, selected);
            addState(new int[] {}, color);
        }
        public void setColor(int color) {
            mColor.getPaint().setColor(color);
            mColor.invalidateSelf();
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the default selector, long-pressing a list item causes its background to transition between
We have this default feature in android 3.0 that when we long press somewhere
My requirement is : List all sales route & highlight default, It should be
I'm trying to make it so that as long as a user is touching
When on android default browser long press on the back key opens the history
How to make android EditText smaller than default in height? If I change the
When you createa a PreferenceScreen on Android, your application creates a default SharedPreferences file
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
Android comes with lots of system resources ( android.R ) that can be used
Why import org.apache.commons.lang.StringUtils cannot be imported in android by default. Do i have to

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.