【问题标题】:I want to make a button with timer?我想制作一个带计时器的按钮?
【发布时间】:2018-11-11 08:53:57
【问题描述】:

我想在 Android 中制作一个带计时器的按钮,如果用户单击此按钮,则该按钮在 30 分钟之前不起作用。时间将显示在此按钮的右侧。 任何机构都可以帮助我解决这个问题?
谢谢你

【问题讨论】:

  • 你能发布你到目前为止尝试过的东西吗?

标签: android android-studio android-layout button


【解决方案1】:

试试这个代码:

int minutes = 30;
int seconds = 60;

//here in id place your button id
Button button = (Button)findViewById(R.id.button_id)

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
    ((Button) findViewById(R.id.click)).setEnabled(false);

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {

           \\ your button action here

        }
    },minutes*seconds*1000);

}
});

【讨论】:

  • 我向您展示了如何延迟使用按钮,但您应该在运行函数中编写代码,通过创建新的 timmer 更改按钮上的文本尝试使用此链接中的代码 [ stackoverflow.com/questions/31639105/…
猜你喜欢
  • 2021-09-02
  • 1970-01-01
  • 2017-07-08
  • 1970-01-01
  • 2014-04-14
  • 1970-01-01
  • 1970-01-01
  • 2019-10-06
  • 2022-08-16
相关资源
最近更新 更多