Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们应该避免在Kotlin中使用类型化数组吗?如果是,是否有更新的方法替换Kotlin中的类型化数组?_Kotlin_Typed Arrays - Fatal编程技术网

我们应该避免在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"

你能解释为什么你不想用它吗?你能解释为什么你不想用它吗?