我正在从一本书中学习开发 Android 应用程序,按照说明进行操作后,我最终得到以下结果。当我运行应用程序时,不会显示 setStartUpScreenText()
对象中的文本。
MainActivity.java:
protected void setStartupScreenText(){
TextView planetNameValue = (TextView)findViewById(R.id.DataView1);
planetNameValue.setText(earth.planetName);
}
MainActivity.xml
<TextView
android:id="@+id/DataView1"
android:layout_toRightOf="@+id/TextView1"
android:layout_marginLeft="36dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
最佳答案
确保在更新屏幕中的任何 View 之前调用 setContentView
方法。
关于java - 无法将文本设置到 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19353979/