Skip to content Skip to sidebar Skip to footer

Android View With View.gone Still Receives Ontouch And Onclick

This is confusing me: As far as I have read, a view with setVisibility(View.GONE); should not receive any more touch- or click events. My layout has two parts, which will be visibl

Solution 1:

Do you maybe use animations to show/hide the views? I get this behaviour when I use animations that have android:fillEnabled="true" android:fillAfter="true" Don't understand it, and seems like a bug - if I use animations without fillEnabled/fillAfter, all works as expected...

Solution 2:

If you set setVisibility(View.GONE) after some animation (fade out, for example), then try clearing the animation with clearAnimation(). This is what helped me.

Solution 3:

Try setting clickable property to false using setClickable(false) after setVisibility(View.GONE)

Solution 4:

Yes,mview.clearAnimation() have some issuses but amination.setFillAfter(false);and mview.setClickable(false); WORKS perfect .

Solution 5:

What I expect is happening is that you make a view invisible, but that views children still respond to clicks (ie your view is a ViewGroup). You could do something along the lines of:

privatevoidhideTheChildren(View v){
    if(v instanceof ViewGroup) {
        intcount= ((ViewGroup)v).getChildCount();
        for(intk=0 ; k < count ; k++) {
            hideTheChildren(((ViewGroup)v).getChildAt(k));
        }
        v.setVisibility(View.GONE);
    }
    else {
        v.setClickable(false);
        v.setVisibility(View.GONE);
    }
}

of course then you also have to do the opposite

privatevoidshowTheChildren(View v){
    if(v instanceof ViewGroup) {
        intcount= ((ViewGroup)v).getChildCount();
        for(intk=0 ; k < count ; k++) {
            showTheChildren(((ViewGroup)v).getChildAt(k));
        }
        v.setVisibility(View.VISIBLE);
    }
    else {
        v.setClickable(true);
        v.setVisibility(View.VISIBLE);
    }
}

This has worked for me in the past. I don't currently know of a better way to do this.

Post a Comment for "Android View With View.gone Still Receives Ontouch And Onclick"