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. Medium density resources for v1.5 problems with workaround


I've created three versions of my app logo for the three different
screen densities and placed them in the relevant folders.  I want my
app to be backwards compatiable with v1.5 of Android.  I'm aware from
the following talk at IO that there is a problem with the density
matching in 1.5:

The recommendation was to create two copies of the medium density
drawables folder and append -v3 to the end of one of them which I've
done.  The problem I now have is that Eclipse won't compile the app
and complains that the logo resource is already defined.  Is it best
to move the medium logo to a drawable folder and alias it, or is there
a better solution?


2. Hmm.. CyanogenMod for Galaxy S?

hmm.. menarik.. :P

"Indonesian Android Community [id-android]" 

3. am trying to start my service on device boot up.

4. Which API verifies signature of Apps?

5. Behavior of contact sync

6. i am trying to write an application in which it shud start service by recieving boot_completed action

7. how to show the CPU usage on the real devices?