【发布时间】:2021-10-17 04:54:02
【问题描述】:
我正在尝试将元素的可变列表数组添加到另一个数组数组的可变列表中。在这里,我在locationList 中有值作为 LatLng 对的可变列表,如下所示([lat/lng:(some value,some value),lat/lng:(some value,some value),lat/lng:(some value,一些价值)])。每次调用函数时,我都试图将列表添加到locationlists4。但我只在数组locationlists4[location4.size-1] 的最后一个列表中获取元素(像这样 [[],[],[lat/lng:(some value,some value),lat/lng:(some value,some value) ,lat/lng:(一些值,一些值)])。所有其他数组列表都是空的。
var locationList = mutableListOf<LatLng>()
var locationlists4 = mutableListOf<MutableList<LatLng>>()
private fun onPauseButtonClicked(){
locationlists4.add(locationlist)
}
private fun updateLocationList(location: Location) {
val newLatLng = LatLng(location.latitude, location.longitude)
locationList.value?.apply {
add(newLatLng)
locationList.postValue(this)
}
}
【问题讨论】:
-
显示您在
locationList中添加纬度的代码。 -
我已添加代码
-
locationList对我来说看起来像LiveData,而不是可变列表。你确定这是正确的代码吗? -
我做对了。看来我一直都是对的。每次调用该函数时,我都必须清除
locationList。这就是locationList没有添加到locationlists4的原因
标签: android arrays android-studio google-maps kotlin