How to programmatically disable onClick handler on Android AppWidget Button

Posted by Gaks on Stack Overflow See other posts from Stack Overflow or by Gaks
Published on 2010-04-15T17:20:42Z Indexed on 2010/04/15 17:23 UTC
Read the original article Hit count: 740

I have a Button on appwidget, that I need to 'enable'/'disable' programmatically from a Service.

First idea was to call setBoolean(R.id.buttonid, "setClickable", false) to disable it, but apparently you can't call setClickable remotely.

Another idea was was remove the text label from it with rv.setTextViewText(R.id.buttonid, "") and then remove the click handler by rv.setOnClickPendingIntent(R.id.buttonid, null). Unfortunately passing null to it causes NullPointerException in in android.app.ActivityThread.handleServiceArgs

Is there some other way to programmatically disable/enable appwidget Button? I could just call rv.setViewVisibility(R.id.buttonid, View.GONE) to hide the button completely instead of disabling it. This would however completely break whole widget layout and I would like to avoid it.

The solution I'm using now is hiding the button with setViewVisibility and showing other blank button instead to the keep appwidget layout as it was before.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-widget