1
如果接受true,我有啓動閃爍視圖線程的函數,但如果接收到false,我該如何停止它?停止視圖閃爍線程
private void blinkText(boolean b){
final Handler handler = new Handler();
if(b)
{
new Thread(new Runnable() {
@Override
public void run() {
int timeToBlink = 1000; //in ms
try{
Thread.sleep(timeToBlink);
}catch (Exception e) {
}
handler.post(new Runnable() {
@Override
public void run() {
TextView txt = (TextView) findViewById(R.id.tv);
if(txt.getVisibility() == View.VISIBLE){
txt.setVisibility(View.INVISIBLE);
}else{
txt.setVisibility(View.VISIBLE);
}
blinkText(true);
}
});
}}).start();
}
else
{
// stop blinking
}
}
爲什麼不使用Android動畫呢? –