====================问题描述====================
我想动态更新TextView内容,但是没有反应。有没有相关代码。
====================解决方案1====================
写个定时器。或者写个线程。隔段时间去更新就哦了
====================解决方案2====================
新建个线程来更新textview里面的值,然后使用handler来更新界面!
====================解决方案3====================
class testThread extends Thread{
public void run() {
Message message = new Message();
mHandler.sendMessage(message);
//在handler中更新UI
private Handler mHandler = new Handler(){
public void handleMessage(Message msg) {
textView.setText("你想变的内容");
然后在你的代码中,执行这个线程
====================解决方案4====================
private final Timer timer = new Timer();
private TimerTask task;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
textView.setText("XXXX");
super.handleMessage(msg);
task = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
timer.schedule(task, 1000, 1000);
或者这样也行
====================解决方案5====================
mTestingButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
//开始进行Open-Short的Testing
testDialog = ProgressDialog.show(InitMassage.this, "", "Don't touch the Screen,Open-Short Testing...",true, false);
TimerTask task = new TimerTask(){
public void run(){
//execute the task
testDialog.cancel();
mShortTestNo.setText(" Pass");
System.out.println("1");
}
};
Timer timer = new Timer();
timer.schedule(task, 6000);
System.out.println("2");
}
});
我使用以上为什么不能在延迟6s后更改TextView的值为“Pass”,系统会自动崩溃!