views:

63

answers:

1

If I set my ImageView to be both clickable and focusable, it works, but I have no way to tell which image is focused. What's the best way to get it to draw an orange border around the view so the user knows it's currently in focus?

I tried dropping it in a LinearLayout and setting that to be focusable and clickable instead, but didn't have any luck. Even when I put a margin on it, there's nothing to indicate that it was selected.

A: 

The quick solution is to use a listener, which will respond to the click, and set an orange border on the imageView...

imageView.setOnClickListener(listener)

But you have to do that for all the ImageView items. At least they can share the same listener.

The long solution is to implement your own View, extending ImageView, which draws its own orange border in response to a click.

I assume you want this to work like radio buttons, where clicking on an ImageView will remove the border from the previously selected ImageView? So you will need the shared listener to maintain a reference to the currently selected ImageView, which can then be "de-selected" when a new ImageView is clicked.

Andy
I have the clicking working OK, it's the focusing that's the problem I need help with. When it's focused, there's no indication of which image has the focus. You can't tell, because the UI doesn't change. I could setOnFocusListener, but any suggestions on how to draw an orange box around my image?
zoonsf