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?