【发布时间】:2013-08-11 20:56:32
【问题描述】:
如何通过调用 settext 方法修改标签信息的文本?
例如根据按下的按钮,我想适当地设置标签的文本
当我尝试访问标签时出现此错误:
不能在不同的内部类中引用非最终变量 i 方法
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);
【问题讨论】:
标签: java android libgdx tablelayout