如何在单击后立即禁用按钮 [英] How to disable button as soon as its clicked
问题描述
我有一个按钮,点击它会加载另一个活动,但在它加载另一个活动之前,如果我连续点击它,然后它会启动该活动,但同一个活动会加载两次或更多次.我在 button.setOnClickListener...onClick 之后不久就尝试过 button.setEnabled(false)但这并没有禁用按钮,我也在点击按钮后立即记录文本,因此根据我的点击,即使我点击了 10 次,它也会记录文本 2 或 3 次.我在这里的感觉是在按钮可以收听点击事件之前,我点击它的速度非常快,以至于我点击它时它会收听所有这些事件.
I have a button which on Click loads another activity, but before it loads another Activity if i tap it continuously, then it launches the activity but the same activity is loaded two times or more. I have tried button.setEnabled(false) soon after button.setOnClickListener...onClick but that is not disabling the button, i am also logging a text as soon as the button is tapped, thus depending on my taps it logs the text 2 or 3 times even if i had tapped it 10 times. What i feel here is before the button can listen to tap events, i am tapping it so fast that it listens to all those events as many times as i tap it.
因此我需要一些按钮可以只听一击然后禁用它的东西.
Thus i need something where the button can just listen one tap and then disable it.
请帮忙
推荐答案
它的已知问题.基本上你可以设置标志.
Its known issue.Basically u can set the flag.
int flag=1;
@Override
public void onClick(View v)
{
if(flag)
{
button.setEnabled(false);
Log.d("ins", "called");
}
flag=0;
}
这篇关于如何在单击后立即禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!