可以禁用一个片段吗?

huangapple go评论76阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年1月3日 20:09:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定