0

I want to be able to set the text of buttons using the strings xml file. I have this code;

Button playVid = (Button)this.findViewById(R.id.vidbutton1);
playVid.SetText(this.getApplicationContext().getString(R.string.play_video));

And this xml

<string name="play_video">Play Video</string>

But I get the compile

error: cannot resolve method settext(java.lang.string)

I am using Android Studio. Everywhere I have read suggest that you can use strings to set text (makes sense, right?), so I am very confused.

This also will not work:

playVid.SetText("Test");

Bug in AS?

1
  • 2
    the error message does not match your code. Commented Aug 5, 2014 at 20:54

3 Answers 3

1

Mind your casing. Use setText() instead of SetText().

Also there's an overload setText(int) that takes in a resource id. You can use it to set a value from resources without using getString() to obtain it yourself first.

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

Comments

1

Methods in Java usually start with a lower-case letter. Maybe that's what your problem is here.

Try playVid.setText("Test"); instead of playVid.SetText("Test");

Comments

0

This works perfectly fine:

Button button = (Button) findViewById(R.id.some_button);
button.setText(R.string.hello_world);

Make sure you imports are correct ;)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.