在运行时在 TextView 中设置文本

Pie*_*tro 1 android runtime textview settext

我是 Android 开发的新手,所以我可能被淹没在一英寸的水中...
我有一个 layout.xml 文件,其中包含一个 TextView 和一些按钮,在我需要的地方设置它们。有没有办法只更改显示的文本而不必以编程方式重新创建整个布局?谢谢你的耐心 :D

Nul*_*ter 5

定义您的TextViewin 后onCreate(),只需调用setText(string)属性。

编辑:

setContentView(R.layout.your_current_layout);
TextView mytextview = (TextView) findViewById(R.id.textView1);
mytextview.setText("I'm called from your activity");
Run Code Online (Sandbox Code Playgroud)

享受 :-)