我有一个可变的汽车列表(汽车是一个数据类)。我正在寻找一种方法来在可变列表中查找具有特定 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) 我有一个清单
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 中是否有重复的条目,如果有,有多少?
下面的代码如何编译才不会出现错误?
var linkedList: MutableList<Int> = java.util.LinkedList()
Run Code Online (Sandbox Code Playgroud)
当java.util.LinkedList类契约显然没有实现 Kotlin 接口时MutableList?
您好我学习用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) kotlin ×4
mutablelist ×4
android ×2
data-class ×1
java ×1
linked-list ×1
list ×1
mapped-types ×1
model ×1