package?com.zxx.handler;
import?android.R.integer;
import?android.app.Activity;
import?android.os.Bundle;
import?android.os.Handler;
import?android.view.Menu;
import?android.view.MenuItem;
import?android.widget.ImageView;
import?android.widget.TextView;
public?class?MainActivity?extends?Activity?{
?private?TextView?tvTextView;
?private?ImageView?ivImageView;
?private?int?index;
?private?MyRunnable?mrMyRunnable?=?new?MyRunnable();
?private?Handler?mHandler?=?new?Handler();
?private?int?images[]?=?{R.drawable.ic_launcher,R.drawable.ic_launcher1};
class?MyRunnable?implements?Runnable{
?@Override
?public?void?run()?{
??//?TODO?Auto-generated?method?stub
??index++;
??index=index%3;
?????ivImageView.setImageResource(images[index]);
??mHandler.postDelayed(mrMyRunnable,?1000);
?}
}
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
??setContentView(R.layout.activity_main);
??tvTextView?=?(TextView)?findViewById(R.id.tv1);
??ivImageView?=?(ImageView)findViewById(R.id.imageView1);
??mHandler.postDelayed(mrMyRunnable,?1000);
//??new?Thread(){
//???public?void?run()?{
//????try?{
//?????Thread.sleep(1000);
//?????mHandler.post(new?Runnable()?{
//??????
//??????@Override
//??????public?void?run()?{
//???????//?TODO?Auto-generated?method?stub
//???????tvTextView.setText("用handler更新了ui");
//???????
//??????}
//?????});
//????}?catch?(InterruptedException?e)?{
//?????//?TODO?Auto-generated?catch?block
//?????e.printStackTrace();
//????}
//???};
//??}.start();
????}
}
2017-10-05
我知道了,我只有2個(gè)圖,我卻寫的%3,我改成%2就對(duì)了,哈哈