0
我有三個Switches
。我想要的是當我點擊另外兩個變成殘疾人。禁用所有其他開關當啓用一個
我所做的是將一個setCheckedListener設置爲它們中的每一個,當我檢查一個時,我將其他兩個的選中狀態設置爲false。
的代碼是:
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
switch (compoundButton.getId()) {
case R.id.switch_most_popular:
mostViewedSwitch.setChecked(false);
latestUpdatedSwitch.setChecked(false);
break;
case R.id.switch_most_viewed:
mostPopularSwitch.setChecked(false);
latestUpdatedSwitch.setChecked(false);
break;
case R.id.switch_latest_updated:
mostPopularSwitch.setChecked(false);
mostViewedSwitch.setChecked(false);
break;
default:
Log.i(TAG, "no checked Switch ");
break;
}
}
與此代碼會發生什麼情況是,我需要時間去觸摸開關。第一次禁用那個是被選中的,第二次是啓用我檢查過的。
我應該更改上面的代碼,以便實現我想要的行爲?或者有沒有其他的選擇用於這個用例? 感謝
請參閱下面的答案。 –
哈哈問題。你嘗試使用谷歌? – GensaGames