0

I have a MediaRouterButton for chromecast in my android device. Now i want to programmatically enable/disable its click, so I have such line of code:

mediaButton.setClickable( false ).

But it doesnt disable its click , the chromecast dialog still show up.

I try checking the source code for it, it overrides the performClick() method, but after I set a break point to this method and debug, i find no methods in the stack other than this performClick().

Can anyone tell me why this is happening?

Qing
  • 1,401
  • 2
  • 21
  • 41
  • use setEnabled() instead of setClickable() – Selva Dec 30 '15 at 10:14
  • it doesnt work... mediaroutebutton is actually extending from view directly instead of a butoon – Qing Dec 30 '15 at 10:19
  • What you are trying to do is against the intended design for the Cast button, what is your use case? – Ali Naddaf Dec 30 '15 at 18:58
  • when I swipe up my main Imageview i want to set the alpha value to all my buttons in toolbar fading away as well as disable them, – Qing Dec 31 '15 at 02:36
  • and I wanna know why it is happening? the button is just extending from a view class, why i cant set it to unclickable? thank you bro – Qing Dec 31 '15 at 02:37

1 Answers1

0

Finally i have a work around....

Just override the MediaRouteButton, override its performClick() method, insert the logic you wanna do.

public class CustomizedChromesCastButton extends MediaRouteButton {
    private boolean enable = true;
    public CustomizedChromesCastButton( Context context ){
        super( context );
    }
    public CustomizedChromesCastButton(Context context, AttributeSet attrs){
        super( context, attrs );
    }
    public CustomizedChromesCastButton(Context context, AttributeSet attrs, int defStyleAttr){
        super( context, attrs, defStyleAttr );
    }

    public void setCastEnable( boolean enable ){
        this.enable = enable;
    }

    public boolean performClick(){
        if( enable ){
            return super.performClick();
        }
        else {
            return false;
        }
    }
}
Qing
  • 1,401
  • 2
  • 21
  • 41