线程练习中出现的错误


public
class MainActivity extends Activity { //1.define member variable Button bt; TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //2.init init(); //3.listener bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new Thread() { public void run() { try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i=0;i<10;i++) { tv.setText("After Update:"+i); } } }; } }); } private void init() { // TODO Auto-generated method stub bt=(Button)this.findViewById(R.id.bt); tv=(TextView)this.findViewById(R.id.tv); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }

1.自己写一遍线程的时候头脑非常简单,直接在子线程里tv.setText("After Update:"+i);

你怕是个猪哦^(* ̄(oo) ̄)^

主线程和子线程不进行交互你怎么会看得到哦

傻逼

 

2.Thread你不start怎么让人家运行呀 记得start

new Thread{
        //......
}.start();

 

3.

运行之后字符串为啥这样

记得是msg.obj !!

 

 

4.是handleMessage不是HandleMessage

 

posted @ 2017-09-22 08:56  喂鲨鱼  阅读(154)  评论(0编辑  收藏  举报