views:

51

answers:

2

Hi, how can i change the text of a button programming a widget?

Tnks, Valerio

A: 

You can use the setText() method. Example:

Button p1_button = (Button)findViewById(R.id.Player1);
p1_button.setText("Some text");

Also, just as a point of reference, Button extends TextView, hence why you can use setText() just like with an ordinary TextView.

eldarerathis
But on a widget findViewById doesn't exist
Skatephone
@Skatephone: It will be easier to help you if you post a little bit of code, then. That being said, the `RemoteViews` class has a `setTextViewText()` method. I'd suggest taking a look at that: http://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewText%28int,%20java.lang.CharSequence%29
eldarerathis
@Skatephone: You shouldn't call findViewById on a Widget, but on an Activity or a View.
benvd
When i receve of a certain button pressed in the onReceive method i try this: RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); remoteViews.setTextViewText(R.id.ButtonMeno, "-");
Skatephone
A: 

I resolved with "remoteViews.setTextViewText(R.id.Counter,"Text");"

Skatephone