Android widget: How to change the text of a button Android widget: How to change the text of a button android android

Android widget: How to change the text of a button


You can use the setText() method. Example:

import android.widget.Button;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.


I was able to change the button's text like this:

import android.widget.RemoteViews;//grab the layout, then set the text of the Button called R.id.Counter:RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.my_layout);remoteViews.setTextViewText(R.id.Counter, "Set button text here");


This is very easy

Button btn = (Button) findViewById(R.id.btn);btn.setText("MyText");