我尝试用setEnable(false)和setClickable(false)分别将radioButtonGroup设置为禁用和不可点击,但这两种方法都不起作用。我如何才能做到这一点?
private boolean isFastMenuItemChange(long time)
{
long curTime = System.currentTimeMillis();
long timeSpace = curTime - lastClickTime;
if (0 < timeSpace && timeSpace < time) {
return true;
}
return false;
}
public void onRadioButtonClicked(View view){
if(isFastMenuItemChange(2000))
{
mBottomRadioGroup.setEnabled(false);
mBottomRadioGroup.setClickable(false);
mBottomRadioGroup.setFocusable(false);
mBottomRadioGroup.setFocusableInTouchMode(false);
return;
}
lastClickTime = System.currentTimeMillis();
mBottomRadioGroup.setEnabled(true);
mBottomRadioGroup.setClickable(true);
mBottomRadioGroup.setFocusable(true);
mBottomRadioGroup.setFocusableInTouchMode(true);
//And so on..
}发布于 2015-09-29 20:30:18
setFocusableInTouchMode(false);
setFocusable(false);
setClickable(false);发布于 2015-09-29 21:34:42
我最终编写了一个方法,用于逐个禁用RadioButtonGroup中的所有元素,然后在所需的几秒钟后重新启用它们。我在我的onRadioButtonClick方法上使用了这个空方法。以下是我的解决方案
private void radioButtonDisabler(){
for(int i = 0; i < mBottomRadioGroup.getChildCount(); i++){
mBottomRadioGroup.getChildAt(i).setEnabled(false);
}
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
for(int i = 0; i < mBottomRadioGroup.getChildCount(); i++){
mBottomRadioGroup.getChildAt(i).setEnabled(true);
}
}
}, 1000); //Re-enable after each one after desired time.
}https://stackoverflow.com/questions/32843894
复制相似问题