我们应该避免在Kotlin中使用类型化数组吗?如果是,是否有更新的方法替换Kotlin中的类型化数组?
下面是我的代码,其中该类用于膨胀视图。 我在这里使用类型化数组。有没有其他方法可以编写此代码 不使用类型化数组 有没有其他方法可以不使用类型化数组编写此代码 否,因为我们应该避免在Kotlin中使用类型化数组吗?如果是,是否有更新的方法替换Kotlin中的类型化数组?,kotlin,typed-arrays,Kotlin,Typed Arrays,下面是我的代码,其中该类用于膨胀视图。 我在这里使用类型化数组。有没有其他方法可以编写此代码 不使用类型化数组 有没有其他方法可以不使用类型化数组编写此代码 否,因为TypedArray类负责包含Android资源的属性值 但是,您可以在Kotlin中使用使其变短: context.withStyledAttributes(attributeSet,R.styleable.CalculatorInputView){ val textResource=getString(R.styleable.C
TypedArray
类负责包含Android资源的属性值
但是,您可以在Kotlin中使用使其变短:
context.withStyledAttributes(attributeSet,R.styleable.CalculatorInputView){
val textResource=getString(R.styleable.CalculatorInputView\u item\u text)
}
请记住,您需要在build.gradle中包含它们:
implementation "androidx.core:core-ktx:1.2.0"
有没有其他方法可以不使用类型化数组编写此代码
否,因为TypedArray
类负责包含Android资源的属性值
但是,您可以在Kotlin中使用使其变短:
context.withStyledAttributes(attributeSet,R.styleable.CalculatorInputView){
val textResource=getString(R.styleable.CalculatorInputView\u item\u text)
}
请记住,您需要在build.gradle中包含它们:
implementation "androidx.core:core-ktx:1.2.0"
你能解释为什么你不想用它吗?你能解释为什么你不想用它吗?