How to make a button/drawable remain clicked

by k_pip_k » Fri, 18 Sep 2009 03:41:14 GMT

Sponsored Links
 Hello all,

I have a GridView with a BaseAdapter that cycles through the elements
making views for each element or cell in the grid.

What I would like to do is create a clickable image/button, and when
the user clicks or touches it, for it to remain clicked and
highlighted so that they make click on several if they so choose.

I have tried, ImageButtons, Buttons, ImageViews, LayerDrawables(with a
swapable background color drawable), ToggleButtons, CheckBoxes,
derived my own CompoundButton, but nothing seems to work.

I was a teeny bit successful with a ImageButton where I could create
it selected, but if the user clicked on it, I couldn't get that visual
state back.

Any help is appreciated.  I can post code if you like.


How to make a button/drawable remain clicked

by BJP » Fri, 18 Sep 2009 15:40:19 GMT

 For whatever reason, this is a pet peeve of some of the core Android
development team.  There have been a number of posts where developers
have requested the ability to programmatically highlight objects as if
the track ball was used to select them but the answer is that this is
impossible in "touch mode" which is entered whenever the user touches
the screen.  The core Android developers claim that highlighting
objects programmatically will present a confusing user experience, so
they're not going to let developers do it.  As far as I know, your
only alternative is to make your own View that behaves like you want
it to, but that will be frowned upon:

Sponsored Links

How to make a button/drawable remain clicked

by k_pip_k » Sat, 19 Sep 2009 04:43:30 GMT

 Thanks, Very strange they don't provide this capability.

I'm writing a game where this is crucial.

Anyways, I did have to implement my own view and managed to get the
LayerDrawable working to accomplish this.  Works pretty good.

> upon:

Other Threads

1. Could you help me?

Hi, glad to see you.
I had a question about Android code, could you help me?
Now I want to create an icon that could be move with such as animation
or others on the screen, and it also could handle the click event.
First, I used class Drawable to create the icon, it can move through
animation, but it can not support click event, because there is no
listener in it.
Second, I used View to create it, it can move through animation too,
but when it moved, only the area where we set it through layout
(int,int,int,int) can get the click event. how could I do to make it
move and can be clicked on where is move to? Thanks very much.
If you knows, could you tell me? My Email is,


2. Outdated link on new android web site

Hi there!

The "Learn more..." link to the "Developers" section of the new
android web site ( is outdated/wrong.

It points to the former android web site instead of



3. Integrating a Search API

4. i would not launch the application

5. OnTouch Event in Emulator

6. problem with "Could not find helloAndroid.apk!"

7. How to set a UID of my apk to AID_ROOT or AID_SYSTEM?