我想使用搜索查询从房间表中获取数据,并将结果显示在 LazyColumn 中,而不是我在那里显示的 someList 中。
换句话说,如何使用 compose from room table 实现搜索功能?
//Getting the list from room and presenting it in lazy column
val someList by mainViewModel.getSomeItems.collectAsState(initial = emptyList())
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
itemsIndexed(items = someList) { itemIndex, item ->
//not really important to the question
item.currentInventory?.let {
MainScreenItemRow(
itemId = item.id,
itemNumber = item.itemNumber,
itemDescription = item.itemDescription,
currentInventory = it,
)
}
}
}
} // end of lazy
Run Code Online (Sandbox Code Playgroud)
我想使用 DAO 查询并在查询与“someList”中的项目之一匹配时显示结果列表。
@Query("SELECT …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序开发购物车功能。我希望分别添加/减少 LazyColumn 中每个列表项的数量。我只使用一个“记住”,因此如果我单击添加/减少,它们都会同时更新。如何单独控制每个项目?
@Composable
fun InventoryCartScreen(
mainViewModel: MainViewModel = hiltViewModel()
) {
val multiSelectValue = mutableStateOf(0)// This is the value I want to change
//random list
val shopList = listOf(
ShoppingList(id = 0,itemNumber = "1",itemDescription = "1",currentInventory = 0,optimalInventory = 0,minInventory = 0),
ShoppingList(id = 0,itemNumber = "2",itemDescription = "2",currentInventory = 0,optimalInventory = 0,minInventory = 0)
)
Column(...) {
LazyColumn(...) {
items(items = shopList, key = { it.id }) { item ->
InventoryCartScreenContents(
onaddClick= { multiSelectValue.value ++ }, //adds …Run Code Online (Sandbox Code Playgroud)