0

I need to implement a generic method which makes View-objects clickable. This is my current implementation:

public static <V extends View> V clickable(V view, OnClickListener listener) {
    view.setFocusable(true);
    view.setClickable(true);
    view.setFocusableInTouchMode(true);
    view.setOnClickListener(listener);
    return view;
}

It works. The problem now is to add visual feedback for the user. I would like to somehow visualize the focus and the click.

An example would be the section titles in Google Play Store. The section titles look like normal text with a fake button, but when touching them, the whole background (text and fake-button) changes.

I know about the solution with xml-files, where I have to specify <selector> and <item android:state_pressed="true"> and so on.

But how to implement the focus/click visualization in my generic method?

Witek
  • 6,160
  • 7
  • 43
  • 63

1 Answers1

0

you can assign a background drawable to the view which has selectors defined in it using:

setBackground setBackgroundResource

you may have to qualify the call based on the platform if you are supporting older phones.

mjstam
  • 1,049
  • 1
  • 6
  • 5
  • Isn't there already a generic "background drawable" defined in android default theme which I could use? For example that one, which is used by ListView... – Witek Mar 30 '15 at 06:47