0

I have tried to do like this,

findViewById(R.id.button1).setText("HI");

But it is not working. is there any other way to do it?

5 Answers 5

2
((Button) findViewByid(R.id.button1)).setText("Hi");

Not sure what you are trying to realize though!

Sign up to request clarification or add additional context in comments.

Comments

1

try this way

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

Comments

0

Try this

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

Comments

0

have to create a button object. if you want to change the name in another class, define the button object global

      import android.widget.Button;

      Button button = (Button)findViewById(R.id.button1);
      button.setText("text change");

Comments

0

Try this

((Button) findViewByid(R.id.button1)).setText("Hi");

If you are trying to instantiate button inside subclass like adapters or dialogs etc , use the respective view before findViewByid.

((Button) view.findViewByid(R.id.button1)).setText("Hi");

or

((Button) dialog.findViewByid(R.id.button1)).setText("Hi");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.