Java/XML - 更改 TextView [英] Java/XML - Change TextView
本文介绍了Java/XML - 更改 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能解释一下为什么这段代码不起作用?我想用 Java 代码更改 textview 的文本,但没有任何变化.
Can someone explain me why this code doesn't work? I want to change the text of the textview with Java code but nothing changes.
package com.example.gethtml;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
GetCode getCode = new GetCode();
Affiche affiche = new Affiche();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
getCode.getCode();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
推荐答案
通过java代码改变textview
文本的代码应该至少包含一个TextView
对象从...开始.我在您的代码中看不到这一点.但我正在为此编写示例代码.
Code to change the textview
's text through java code should contain at least one TextView
object to start with. I can not see that in your code. But I am writing below a sample code for that.
setContentView(R.layout.activity_main);
TextView txtView = (TextView) findViewById(R.id.txtview);
txtView.setText("This is changed text");
您的 activity_main.xml
应包含用您所指的 id 定义的 TextView
.希望有帮助.
Your activity_main.xml
should contain TextView
defined with id you are referring. Hope it helps.
这篇关于Java/XML - 更改 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文