我有一个TextView
我想更新TextView
每 5 秒对字符串数组中的每个字符串进行一次。
这是我尝试过的代码。它始终仅显示字符串数组中的最后一个字符串。
TextView display;
EditText caption;
Thread thread;
String blinks;
String[] wc;
private CountDownTimer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = (TextView) findViewById(R.id.display);
caption = (EditText) findViewById(R.id.caption);
timer = new CountDownTimer(5000, 20) {
@Override
public void onTick(long millisUntilFinished) {
String[] wc = {"The","Qucik", "Brown","fox","Jumped"};
for (int j = 0; j < wc.length; j++) {
blinks = wc[j];
final String[] titles = {"" + blinks + ""};
for (int i = 0; i < titles.length; i++) {
display.setText(titles[i]);
}
}
}
@Override
public void onFinish() {
try{
yourMethod();
}catch(Exception e){
}
}
}.start();
}
final String[] wc = {"The", "Qucik", "Brown", "fox", "Jumped"};
final android.os.Handler handler = new android.os.Handler();
handler.post(new Runnable() {
int i = 0;
@Override
public void run() {
display.setText(wc[i]);
i++;
if (i == wc.length) {
handler.removeCallbacks(this);
} else {
//5 sec
handler.postDelayed(this, 1000 * 5);
}
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)