利用Handler改变UI,整了一天了,就是找不到错误,完全按照李刚的疯狂android讲义来的,就是不知道哪错了。
错误在附件图片里,看着直观些。
这个是源码:package com.fangyan.add;
import java.util.Timer;
import java.util.TimerTask;import com.fangyan.R;import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.Button;@SuppressLint("HandlerLeak")
public class AddVoiceActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_voice);

final Button addVoiceBu = (Button)this.findViewById(R.id.add_voice_bu);

final Handler handler = new Handler(){
public void handleMessage(Message mes){
Log.e("请求", "handler");
if(mes.what==0x0011)
addVoiceBu.setText("ab\ncd");
}
};
new Timer().schedule(new TimerTask(){
public void run() {
Message mes = new Message();
mes.what = 0x0011;
handler.handleMessage(mes);
}

}, 0, 1000);

}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_sound, menu);
return true;
}
}