问题是,当我第二次单击按钮时,我的应用程序崩溃了,我不明白为什么。当我第二次点击按钮时,假设再次相同。
任何帮助表示赞赏。
public class main extends Activity {
Boolean grabar = false;
TextView texto;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
texto = (TextView) findViewById(R.id.texto);
Button startbtn = (Button) findViewById(R.id.button);
startbtn.setOnClickListener(new OnClickListener(){
public void onClick(View v){
background.start();
}
});
}
Thread background = new Thread (new Runnable() {
public void run() {
try {
Thread.sleep(3000);
cambiarHandler.sendEmptyMessage(0);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Handler cambiarHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
texto.setText("ok");
}
};
}