标签: mutablelist

Android Kotlin:在 mutableList 中搜索具有特定键值的元素

我有一个可变的汽车列表(汽车是一个数据类)。我正在寻找一种方法来在可变列表中查找具有特定 id 的汽车。我怎样才能在 Kotlin 中实现这一目标?

卡.kt

data class Car(
    val createdAt: String = "",
    val updatedAt: String = "",
    val id: String = "",
    val number: String = ""
)
Run Code Online (Sandbox Code Playgroud)

在我的CarsFragment.kt中:

var cars: MutableList<Car>

// extract Car with id = "89Ddzedzedze8998" ?
Run Code Online (Sandbox Code Playgroud)

android kotlin mutablelist

1
推荐指数
1
解决办法
6264
查看次数

Kotlin 在 mutableList 中查找重复项

我有一个清单

 val shoeCart = ShoeRepository.getShoeFromCart(this@ActivityCart)
Run Code Online (Sandbox Code Playgroud)

来自鞋库

 fun getShoeFromCart(context: Context): List<ShoeModel> {
    return getCart(context)
}
Run Code Online (Sandbox Code Playgroud)

ShoeModel 是一个数据类

data class ShoeModel
Run Code Online (Sandbox Code Playgroud)

我想知道我的 ShoesCart 中是否有重复的条目,如果有,有多少?

model list kotlin data-class mutablelist

1
推荐指数
1
解决办法
4206
查看次数

java.util.LinkedList() 如何成为 MutableList 的实例?

下面的代码如何编译才不会出现错误?

var linkedList: MutableList<Int> = java.util.LinkedList()
Run Code Online (Sandbox Code Playgroud)

java.util.LinkedList类契约显然没有实现 Kotlin 接口时MutableList

java linked-list kotlin mapped-types mutablelist

1
推荐指数
1
解决办法
95
查看次数

如何修复Kotlin中必需的Iterable但找到列表

您好我学习用kotlin构建应用程序,但是我收到此错误消息,提示“ Required Iterable,Found List”,我该如何解决此问题?请在下面查看我的代码谢谢

class MainActivity : AppCompatActivity(),ProductView {

private lateinit var productAdapter: ProductAdapter
private var productList: MutableList<ProductData> = mutableListOf()
private lateinit var dataPresenter : DataPresenter

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    initRecycler();
    getProduct()
}

private fun getProduct() {
    dataPresenter = DataPresenter(applicationContext,this)
    dataPresenter.getProduct()
}

private fun initRecycler() {
    productAdapter = ProductAdapter(this,productList)
    rvMain.layoutManager = LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
    rvMain.adapter = productAdapter
}

override fun showLoading() {
    pgMain.visibility = View.VISIBLE
}

override fun hideLoading() {
    pgMain.visibility = View.GONE
}

override fun showProduct(products: List<ProductData>?) { …
Run Code Online (Sandbox Code Playgroud)

android kotlin mutablelist

0
推荐指数
1
解决办法
199
查看次数