beginButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
PlayThread playThread = new PlayThread();
Thread thread = new Thread(playThread);
thread.start();
}
});
public class PlayThread implements Runnable {
@Override
public void run() {
beginButton.setClickable(false);
pauseButton.setClickable(true);
messageBool = true;
int maxProgressBar = playProgressBar.getMax();
int currentInt = playProgressBar.getProgress();
for(; currentInt <= maxProgressBar; ++currentInt)
{
if(messageBool == false)
{
break;
}
playProgressBar.incrementProgressBy(1);
try {
Thread.sleep(400);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(currentInt > maxProgressBar)
{
playProgressBar.setProgress(0);
beginButton.setClickable(true);
pauseButton.setClickable(false);
}
}
};
大家好。这段代码有问题吗?我知道我们不能在除UI thread之外的其他线程中操作 UI 的控件。但是这段代码运行正常。那么有什么问题或者我想念什么?提前致谢!