我有三根弦在订单
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