我有以下密封类:
sealed class Pot(
val ball: Ball,
val potType: PotType,
val potAction: PotAction
) {
class HIT(hitBall: Ball) : Pot(hitBall, PotType.HIT, PotAction.CONTINUE)
object SAFE : Pot(Ball.NOBALL, PotType.SAFE, PotAction.SWITCH)
object MISS : Pot(Ball.NOBALL, PotType.MISS, PotAction.SWITCH)
class FOUL(foulBall: Ball, foulAction: PotAction): Pot(foulBall, PotType.FOUL, foulAction)
class REMOVERED(removeBall: Ball): Pot(removeBall, PotType.REMOVERED, PotAction.CONTINUE)
object ADDRED: Pot(Ball.RED, PotType.ADDRED, PotAction.CONTINUE)
}
我希望将此从xml传递给视图模型:
<data>
<import type="com.example.snookerscore.fragments.game.Pot"/>
// other variables
</data>
然后我在需要将信息传递给click处理程序的视图中使用lambdas:
<TextView
android:id="@+id/game_btn_act_safe"
style="@style/temp_btn"
android:onClick="@{() -> gameViewModel.updateFrame(Pot.SAFE)}"
// Other view Properties
/>
我得到这个错误:
找不到标识符“pot”。检查标识符的拼写是否正确,并且没有或标记丢失。
我也尝试过直接导入pot.safe
,但仍然不起作用
使用的;
<variable
name = "sealedName"
type="com.example.snookerscore.fragments.game.Pot"/>
已删除
<import type="com.example.snookerscore.fragments.game.Pot"/>
最终;
android:onClick="@{() -> gameViewModel.updateFrame(sealedName.SAFE)}"