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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:05:39+00:00 2026-06-09T13:05:39+00:00

After changing my code around ( first attempt ) I am having a similar

  • 0

After changing my code around (first attempt) I am having a similar problem. I have updated my getView() to execute the proper way.

@Override
public View getView( int position, View convertView, ViewGroup parent ) {
    Resources res = activity.getResources();

    if( convertView == null ) {
        LayoutInflater vi = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate( R.layout.video_gallery_item, parent, false ); 
    }

    Bitmap bmp = getBitmap( videoIds[ position ] );

    /* This layer drawable will create a border around the image. This works */
    Drawable[] layers = new Drawable[ 2 ];
    layers[ 0 ] = new BitmapDrawable( res, bmp );
    layers[ 1 ] = res.getDrawable( R.drawable.border_selected );
    LayerDrawable layerDrawable = new LayerDrawable( layers );

    /* Create the StateListDrawable */
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState( StateSet.WILD_CARD, new BitmapDrawable( res, bmp ) );
    drawable.addState( new int[]{ android.R.attr.state_checked, android.R.attr.state_selected }, layerDrawable );
    ImageView v = (ImageView)convertView.findViewById( R.id.image );
    v.setImageDrawable( drawable );
    v.setAdjustViewBounds( true );
    thumbnails[ position ] = bmp;
    return convertView;
}

This adapter is being use on a GridView called videoGallery:

videoGallery.setChoiceMode( GridView.CHOICE_MODE_MULTIPLE_MODAL );
videoGallery.setMultiChoiceModeListener( new MultiChoiceModeListener() { ... }

The problem I am having is that the images do not change when they are selected on the GridView via long click. The action bar changes, my contextual menu appears, etc. I have also tried creating the StateListDrawable via XML with the same results. Thoughts?

UPDATE

Changing

drawable.addState( new int[]{ android.R.attr.state_checked, android.R.attr.state_selected }, layerDrawable );

to

drawable.addState( StateSet.WILD_CARD, layerDrawable );

in my getView() shows the border I am looking for. So maybe the StateListDrawable isn’t getting the state change? Anybody have any thoughts?

  • 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-09T13:05:41+00:00Added an answer on June 9, 2026 at 1:05 pm

    Well I figured it out. There were a few problems with my states. First in the order:

    drawable.addState( StateSet.WILD_CARD, new BitmapDrawable( res, bmp ) );
    drawable.addState( new int[]{ android.R.attr.state_checked, android.R.attr.state_selected }, layerDrawable );
    

    In the first addState I am using the wildcard. Because of this android would match this state before the one following that. Also, despite android saying the item is “checked” the actual state is “activated”. So I changed the two lines to:

    drawable.addState( new int[] { android.R.attr.state_activated }, layerDrawable );
    drawable.addState( new int[] { -android.R.attr.state_activated }, new BitmapDrawable( res, bmp ) );
    

    And it is working perfectly!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I execute my custom code after all normal processing associated to changing
Trying to find a way to execute a function within BASH after changing into
I have the following code to extend my $_SESSION[] variables. They expire after around
Im having a weird issue here; The following .htaccess works but now (after changing
I know that it is an easy task, but after changing my code it
after changing from a 32 to 64Bit Ubuntu installation my python+ctypes+c99 code is broken.
I have a problem with updating the value of property from code which is
I have a chunk of code where it appears that a variable is changing
I have a very specific problem, and a work around solution will not help.
After changing - #import <Cocoa/Cocoa.h> to #import <UIKit/UIKit.h> - pi to M_PI and disabling

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.