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. posting

I just tried making a post asking about how to implement interaction between
2 players in a game, but when I was done, I got an error message saying that
the post couldn't be made.

Any idea why that might be?

My account is registered under


Marshall Farrier


2. Salam kenal buat semua

Salam kenal buat rekan rekan semua. Saya Silas dari surabaya. Masih newbie. :-)

Sent from Samsung tablet


3. Imap or push yg lebih hemat energi?

4. OOT : BBM porting to Android and IOs : good or bad ???

5. {WTS} LogayPektay High-End Gadget Accessories (ANDROID) "SNS, DHD, DZ, Droid 2/Global, Charm, Droid Pro, DX, etc"

6. WTHelp : Sparepart aPad iRobot

7. Is License Server down at the moment?