Android/Java 通过输入字符串 ID 更改 TextViews 文本的帮助!
正如标题所述,每当我尝试(在我的 java 类中)通过指示 TextView 设置“strings.xml”中列出的字符串的文本来设置 TextView 的文本时,我的程序都会崩溃,如果我删除该调用,则程序运行正常。下面是一个例子。
MediaPlayer dus;
String Stat;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
final TextView T = (TextView) findViewById(R.id.Status);
dus = MediaPlayer.create(DialUpDroidActivity.this, R.raw.dus);
Timer timer;
timer = new Timer();
dus.start();
Stat = getString(R.string.Dial);
TimerTask TxtTimer = new TimerTask() {
public void run() {
T.setText(Stat);
}
};
timer.schedule(TxtTimer, 7000);
}
正如你所看到的,我尝试做 T.setText(Stat);但程序崩溃了。我尝试过 T.setTextView(R.string.Dial);和 T.setTextView("Hello") 两种方法都崩溃了。我做错了什么?
Well as the title states, anytime I try (in my java class) to settext of a TextView by directing it set the text of a string listed in "strings.xml" my program crashes, If i remove that call then the program runs fine. Below is an example.
MediaPlayer dus;
String Stat;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
final TextView T = (TextView) findViewById(R.id.Status);
dus = MediaPlayer.create(DialUpDroidActivity.this, R.raw.dus);
Timer timer;
timer = new Timer();
dus.start();
Stat = getString(R.string.Dial);
TimerTask TxtTimer = new TimerTask() {
public void run() {
T.setText(Stat);
}
};
timer.schedule(TxtTimer, 7000);
}
So as you can see i tried to do T.setText(Stat); but the program crashed. I've tried T.setTextView(R.string.Dial); and T.setTextView("Hello") Both methods crashed. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你初始化你的textview了吗?
Have you initiliazed your textview?
哪里
?
使用
Where is
?
Use