Ad

Why When I Use SetClickable(true) It's Not Show The Action Of Click

- 1 answer

Actually, I use a ListView and when I use setClickable(false) I have the animation as if I clicked on a button you see? The animation that shows you click. Which is not normal, I think, basic.

And when I use setClickable(true) I no longer have the animation, as well as if I use

        convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

And i would like to use the OnClickListener but I think it would be better for the user to see that he can click, so to have the animation when you click.

So, I'd like to see when the user clicks on an item in the list, it does the action I want (I'll add that later) but let's imagine a Toast but it displays the effect as if you click on a button. The effect i got if i use setClickable(false) (the default setting).

That's the ripple effect !

Ad

Answer

In the row's layout of the ListView just add:

android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"

This will add the Ripple effect. If you want to show it on top of the other views, use the forground attribute:

android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
Ad
source: stackoverflow.com
Ad