在android中删除postDelayed

时间:2014-03-05 12:11:13

标签: android textview

我使用postDelayedTextView一段时间后将其隐藏起来。现在,如果用户点击按钮,我想删除postDelayed

我的代码如下:

tvRQPoint.setText("+100");
tvRQPoint.postDelayed(new Runnable() {
    public void run() {
        tvRQPoint.setText("");
    }
}, 10000);

怎么做?

4 个答案:

答案 0 :(得分:1)

在下方的单独位置创建您的主题...

private Runnable mTimerExecutor = new Runnable() {

    @Override
    public void run() {
        tvRQPoint.setText("");
    }
};

然后按如下方式调用它来执行....

tvRQPoint.postDelayed(mTimerExecutor, 10000);

如果要取消postDelay执行,请按以下步骤取消...

tvRQPoint.removeCallbacks(mTimerExecutor);

答案 1 :(得分:1)

检查这个

Runnable runnable = new Runnable() {
  public void run() {
    tvRQPoint.setText("");
  }
 };  

tvRQPoint.setText("+100");
tvRQPoint.postDelayed(runnable, 10000);

将其删除

    tvRQPoint.removeCallbacks(runnable);

答案 2 :(得分:0)

在onClick中使用以下代码。它会删除。

private final Runnable r = new Runnable() {
    public void run() {
            tvRQPoint.setText("");
            Handler handler = new Handler(); 
            handler.postDelayed(this, 2000);
        }
    }
};

然后在onClick按钮

中使用它
handler.removeCallbacks(r);

有关详细信息,请查看此link

答案 3 :(得分:0)

boolean clicked=false;

onClick事件

clicked=true;

和postDelayed

tvRQPoint.setText("+100");
tvRQPoint.postDelayed(new Runnable() {
    public void run() {
        if(!clicked)
           tvRQPoint.setText("");
    }
}, 10000);