Android - 将文本设置为 TextView [英] Android - Set text to TextView
本文介绍了Android - 将文本设置为 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在为一个学校项目学习一些 android,但我不知道如何动态设置文本 到 TextView
.
I'm currently learning some android for a school project and I can't figure out the way to set text dynamically to a TextView
.
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enviar_mensaje);
err = (TextView)findViewById(R.id.texto);
err.setText("Escriba su mensaje y luego seleccione el canal.");
}
这目前不起作用,我找不到使它起作用的方法...
This is currently not working and I can't find a way to make it work...
任何帮助将不胜感激...谢谢你的时间,何塞.
Any help will be much appreciated... Thank you for the time, José.
这里是 activity_enviar_mensaje.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
tools:context=".EnviarMensaje" >
...
<TextView
android:id="@+id/texto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listaVista"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/listaVista"
android:text="TextView" />
...
</RelativeLayout>
不工作是指显示的文本在任何时候都不会改变...
By not working I mean the text shown does not change at any moment...
推荐答案
在你的布局 XML 中:
In your layout XML:
<TextView
android:id="@+id/myAwesomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Escriba el mensaje y luego clickee el canal a ser enviado"
android:textSize="20sp" />
然后,在您的活动课程中:
Then, in your activity class:
// globally
TextView myAwesomeTextView = (TextView)findViewById(R.id.myAwesomeTextView);
//in your OnCreate() method
myAwesomeTextView.setText("My Awesome Text");
这篇关于Android - 将文本设置为 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文