How to disable a button on an appwidget?


SDK Version: 
M3

Would you like to disable a button on an appwidget?
As far as I know it can not be done, since the appwiget UI manipulation is limited by the methods of the RemoteViews class.

But if you insist to do that there is a way to make it look like the button were disabled!

RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.

Lets see a simple example:
We want to have two buttons on the widget, a stop and a start button in order to stop and start some kind of functionality. Once we have started it, we can not start it agin, until we stopped it and vica versa, so we want to disable the button which can not be used right now.

The XML definition of the buttons can be like this:

  1. <Button android:id="@+id/startbutton" android:text="Start" android:visibility="visible"></Button>
  2. <Button android:id="@+id/startbutton_disabled" android:text="Start" android:clickable="false" android:textColor="#999999" android:visibility="gone"></Button>
  3.  
  4. <Button android:id="@+id/stopbutton" android:text="Stop"  android:visibility="gone"></Button>
  5. <Button android:id="@+id/stopbutton_disabled" android:text="Stop" android:clickable="false" android:textColor="#999999" android:visibility="visible"></Button>

The code that runs when clicked on the start button will contain someting like this:

  1. RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
  2. remoteView.setViewVisibility(R.id.startbutton, View.GONE);
  3. remoteView.setViewVisibility(R.id.startbutton_disabled, View.VISIBLE);
  4. remoteView.setViewVisibility(R.id.stopbutton, View.VISIBLE);
  5. remoteView.setViewVisibility(R.id.stopbutton_disabled, View.GONE);
  6. AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteView);

And the same for the stop button:

  1. RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
  2. remoteView.setViewVisibility(R.id.startbutton, View.VISIBLE);
  3. remoteView.setViewVisibility(R.id.startbutton_disabled, View.GONE);
  4. remoteView.setViewVisibility(R.id.stopbutton, View.GONE);
  5. remoteView.setViewVisibility(R.id.stopbutton_disabled, View.VISIBLE);
  6. AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteView);

Comments

How to disable a button on an appwidget?

i have some materials if u want i can share those here, and u can catch me here
horses for sale

Useful Article

Great post! The XML definitions are clear and I just used in my widget. It worked fine. Thanks.

habitat discount code

Sweet mama it works

Wow this thing works. Not bad. Good share man - good share. Just like when Im playing bloxorz all day long. I get tired and want to skip levels thats when I use Google to search for Bloxorz Passcodes and this is how I feel.

Well done Gabor

Thanks for tht Gabor !

Jeux

great thread

this is a great thread for technical knowledge

this is a really good post.

this is a great thread for technical knowledge

Bronx Car Sales

You cannot disable a button

You cannot disable a button on an appwidget since changing the appwiget UI is constrained by the RemoteViews class methods. Search Engine Marketing

I have a Button on appwidget,

I have a Button on appwidget, that I need to 'enable'/'disable' programmatically from a Service.
Van Reviews
How to stop Excessive Sweating

RemoteViews cannot change the

RemoteViews cannot change the enabled/disabled state of buttons, but you can modify its visibility through RemoteViews. You need two buttons, the real one and one that mimics the real button. STD Clinic Singapore

just great!

Just wanted to say I enjoyed the post. You have really put a lot of time into your article and it is just great!
www.telefonkatalogen.biz

Your trick is right Gufler

i read your post Gufler and really appreciate the trick. It works for me. Thanks. Tinnitus Retraining Therapy

We have gave up trying

We have gave up trying different ways to disable it.Trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.Thanks

usa business directory

Excellent work

Excellent work as usual. I was trying to figure this out myself..

LED vs LCD
Door Canopies

Thanks for the tutorials

This trick is very easy and

This trick is very easy and simple to use. Trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state. Thanks for the statement.
website link building

until we stopped it and vica

until we stopped it and vica versa, so we want to disable the button which can not be used right now.
Forexblog

I agree with you

I agree with you gufler. I really do not understand why people do not catch this trick. I use it it works so well. Fat Burning Furnace

Are you interested in PC

Are you interested in PC games? PCGameSupply.com is your trusted source for digitally delivered PC Games, Wii, Xbox and Playstation subscription cards & points. Offering email & download delivery which is guaranteed within 30 minutes of your order.
iTunes Gift Cards

mp3 dinle

Forex Signals

I gave up trying different ways to disable it.Trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
Forex Signals

Forex Signals

RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
Forex Signals

Wow

Great post, bravo!

by waiting I have a problem which nothing to see, but I need some help.

to write in Arabic with a keyboard " normal " that not good with windows.
I will want a simple installation to write in Arabic with my keyboard without spent d 'argent on top of that.

I found this site:
http://www.le-clavier-arabe.fr

It worked, now how can I

It worked, now how can I bring the appwidget back? or can I replace it with a grammar checker widget my friend created? Thanks!

Oh wow..Great approach there

Oh wow..Great approach there for this. I'm totally in awe of your work.

casino

Great tutorial

Dude this article completely explained what I was trying to fix. Your awesome!

wrestling singlets

Trick is to have two buttons,

Trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
mary frances handbag

I faced the problem with the

I faced the problem with the Time Intervals which I have given to the AppWidget(20 sec) and the Location Listener(2 sec). Then both are not synchronized with each other. I set the Time Interval for AppWidget to 1 minute and for Location Listener to 20 seconds. Now it is working fine..

Kodak Digital Frame

Gadgets and Gizmos

Is there some other way to

Is there some other way to programmatically disable/enable appwidget Button? Very good answers.thank you.
Gated Communities

If you insist to do that

If you insist to do that there is a way to make it look like the button were disabled! RemoteViews can’t manipulate a buttons enabled/disabled state, but it can modify its visibility.Thanks
Menopause Treatment

This very cool..

I have applied your techniques and it works great. This is very cool.
Thanks!

effective golf swing tips

Set Visibility

try the xml approach...its simple to integrate and works well.

Mauritius

Brilliant idea, though I'm

Brilliant idea, though I'm curious, does this modify the app layout or does the button end up right where the other one was?banana republic dresses

Javascript

I am using javascript function to hide the button but seems your solution is much simpler. Thanks

CFDs | Spread Betting

The solution I'm using now is

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.
natural gout treatment

I gave up trying different

I gave up trying different ways to disable it.Trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
How to stop my divorce

"Thanks for sharing this. I

"Thanks for sharing this. I also have trouble disable a button on an appwidget. I thought it is not possible anymore so, I gave up trying different ways to disable it.

I'm glad you shared this so I could start now the application. Hopefully, this would be what I really wanted to to with the button in appwidget. Hope to hear more tips from you."

Dutch
My Last Blog Post Revitol Stretch Mark Cream Review

This thread is useful for the

This thread is useful for the technical knowledge finders. I am glad I found it informative so Site has been added to my RSS feed for later browsing. diadora cycling shoesPPI claim

If you insist to do that

If you insist to do that there is a way to make it look like the button were disabled! RemoteViews can’t manipulate a buttons enabled/disabled state, but it can modify its visibility.
CCSVI

Trick is to have two buttons,

Trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
chexsystems

Then both are not

Then both are not synchronized with each other. I set the Time Interval for AppWidget to 1 minute and for Location Listener to 20 seconds. Now it is working fine..rokettube
porno izle
porno izle

How to disable a button on an appwidget?

Thank you for this article, programming on android is cool!

it s like
PIC Devreler
Mp3 dinle

But if you insist

But if you insist to do that there is a way to make it look like the button were disabled!Tenkk very godd.+

Tuning
Tuning
Tuning
Google Tuning

It is also not too effective

It is also not too effective to test everything by having to write SQL statements, so lets see a moore user frendy way, using
graphical

tools, to look into the database. Promotional Merchandise

mobile technology

i have androad materials, if u want u can contact me through my mail from here
horses for sale

This definitely works very

This definitely works very well. The code is setup correctly because we used it at work with great success.
accutane

Thanks

RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch car transport one is visible.

for for the heads up. This

for for the heads up. This really is an awesome tip for an android user like myself.
_________________
SUV and Truck Accesssories | Buy Pet Supplies Online | Xandria Sex Toys

Those Jackson kids are

Those Jackson kids are adorable! What! No mention of Pink's outstanding performance--twirling and splashing water on all the celebs (help I'm melting)

Florida Health Insurance

Is there some other way to

Is there some other way to programmatically disable/enable appwidget Button?
acne treatment

When will they come up of a

When will they come up of a phone application that allows
spelling and grammar check
while texting, creating email or writing a short blog using android phone? I know spell check exists, but is there an application that is combined with grammar checker too?