How do I modify the Lable info's text by calling its settext method?
For e.g. depending in the button pressed I want to set the label's text appropriately
I get this error when I try accessing the label :
Cannot refer to a non-final variable i inside an inner class defined in a different method
Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
stage = new Stage();
Gdx.input.setInputProcessor(stage);
table = new Table();
table.setFillParent(true);
stage.addActor(table);
String sentence = "One two three four five six seven eight";
String[] temp = sentence.split(" ");
ArrayList<String> words = new ArrayList<String>(Arrays.asList(temp));
info = new Label( "Welcome to Android!", skin );
for(int i=0; i<words.size();i++)
{
TextButton button = new TextButton( words.get(i), skin);
table.add(button);
button.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("button","clicked");
//info.setText(Integer.toString(i)); How to make this work?
//also how do I know which button is pressed?
};
});
}
table.row();
table.add(info);
Gdx.input.setInputProcessor(stage);