我有三根弦在訂單
String one="Connecting.";
String two="Connecting..";
String three="Connecting...";
我有一個TextView多次更改文本視圖的文本,我要的是設置文本在此以TextView的.. 一個 - > two-- >三→一→二→三等,直到過程完成。
我已經在基於價值做了它的循環,即
if(value%3==0){
tx.setText(one);
}
else if(value%3==1){
tx.setText(two);
}
else
{
tx.setText(three);
}
This is done inside a thread and it is working well.
,但我不想依靠「價值」。我想JST直到過程完成,以便文本更改提到以上。 我知道這是模糊的,但我沒有得到如何做到這一點。 請如果有人可以給任何提示。
code:
public void startProgress(View view) {
bar.setProgress(0);
tx.setText("Connect");
new Thread(new Task()).start();
}
class Task implements Runnable {
@Override
public void run() {
for (int i = 0; i <= 10; i++) {
final int value = i;
try {
Thread.sleep(500);
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
bar.setProgress(value);
String one="Connecting.";
String two="Connecting..";
String three="Connecting...";
if(value%3==0){
tx.setText(one);
}
else if(value%3==1){
tx.setText(two);
}
else
{
tx.setText(three);
}
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
你使用計時器! – 2014-10-28 10:13:18
請參閱編輯代碼。我不使用計時器。 – 2014-10-28 10:17:08
爲什麼你不使用進度條,看到這個例子http://android-er.blogspot.com/2011/07/display-indeterminate-progress-bar-on.html – 2014-10-28 10:32:23