4

This is an extremely basic question and I'm embarrassed I haven't been able to find the solution online.

I would like to be able to update the text of my button in code. I am using the new Android Studio IDE. I created a blank activity when starting the project and placed a Button in activity_main.xml. How do I access this button in code to change its properties? I am trying in the mainactivity.java file but the intellisense isn't giving me anything that looks promising.

4

2 回答 2

15
Button button = (Button)findViewById(R.id.button);
button.setText("Click Me !");

我希望这可以帮助你。

于 2013-06-05T09:59:06.880 回答
5

// 然后清理代码

按钮按钮 = (Button)findViewById(R.id.button);

于 2013-06-02T03:21:05.307 回答