Monday, 9 September 2013

Why strings are not equal

Why strings are not equal

In my android app, I have a Play button. but after I clicked the button,
nothing happend. Seems when comparing the text on the button, they are not
equal. if I use indexOf(PLAY), it works. Cannot figure out why it behaves
like this. I defined my string values in res/values/strings.xml as
<string name="play">Play</string>
private final static String PLAY = "Play";
//some code in between
Button playButton = new Button(this);
playButton.setText(R.string.play);
playButton.setTextSize(BUTTON_FONT_SIZE);
playButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Button b = (Button) v;
if (b.getText().equals(PLAY)) { //stuck here.
startPlay();
} else {
stopPlay();
}
}
});
Thanks for the help.

No comments:

Post a Comment