我有4个字符串,我想每3秒在1个textview中显示它们,并使其重复.
例如显示某些.png文件的动画列表.
要清楚,我想这样做:
while(true){
tv.SetText("Text1");
//delay for 3 second
tv.SetText("Text2");
//delay for 3 second
tv.SetText("Text3");
//delay for 3 second
tv.SetText("Text4");
//delay for 3 second
}
解决方法:
public class MainActivity extends ActionBarActivity {
private TextView textView;
private int count = 1;
Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
handler.postDelayed(new Runnable() {
@Override
public void run() {
textView.setText(count+"");
count++;
if (count > 3) {
handler.removeCallbacks(this);
} else {
handler.postDelayed(this, 3000);
}
}
}, 0);
}
}