英文:
Is it possible to disable a fragment?
问题
我有两个片段,在每个片段中都有9个按钮。我希望当我点击一个片段时,另一个片段变为启用状态,而我点击的那个变为禁用状态,反之亦然。
我找不到任何可以让我在不使其消失的情况下禁用一个片段的方法。
英文:
I have two fragments, in each fragment there are 9 buttons. I want when I click on a fragment the other is enabled and the one where I clicked is disabled and the opposite.
I can't find anything that allows me to deactivate a fragment without it disappearing.
答案1
得分: 1
I know two methods to get it. The first one is more correct but also is more bulky than the second, so you need add to both fragments a static boolean variable with name for e.g. "isClickable" then when you click on the first fragment set it's "isClickable" variable to false, and the same variable of the second fragment set to true and the opposite, finally add to each of your buttons onClickListeners condition:
if (isClickable) {
// and here do needed actions
}
In the second method, you also need to have the two "isClickable" variables, but also you need to set to each of your fragment's root layout an onTouchListener (exactly onTouch, not onClick) and put to it's return statement the "isClickable" variable but necessary with negation:
return !isClickable
.
英文:
I know two methods to get it. The first one is more correct but also is more bulky than the second, so you need add to both fragments a static boolean variable with name for e.g. "isClickable" then when you click on the first fragment set it's "isClickable" variable to false, and the same variable of the second fragment set to true and the opposite, finally add to each of your buttons onClickListeners condition:
if (isClickable) {
// and here do needed actions
}
In the second method, you also need to have the two "isClickable" variables, but also you need to set to each of your fragment's root layout an onTouchListener (exactly onTouch, not onClick) and put to it's return statement the "isClickable" variable but necessary with negation:
return !isClickable
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论