我有一个包含从 api 提取的数据的列表。但是,我需要对此列表(movieList)进行更改。我需要将索引 0 处的元素与索引 1 处的元素交换。例如:
列表[0] = 电影A,
列表[1] = 电影B
然后
列表[0] = 电影B,
列表[1] = 电影A
我打算执行这些操作的类如下:
data class MovieListDto(
val docs: List<Movie>,
val limit: Int,
val offset: Int,
val page: Int,
val pages: Int,
val total: Int
)
fun MovieListDto.MovieListDtoToMovieList(): List<Movie> {
val movieList = mutableListOf<Movie>()
for (movie in docs) {
if (movie._id == "5cd95395de30eff6ebccde5c" ||
movie._id == "5cd95395de30eff6ebccde5b" ||
movie._id == "5cd95395de30eff6ebccde5d"
) {
movieList.add(movie)
}
}
return movieList
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我对 DropdownMenu 有疑问。当我单击 Morevert 图标时,菜单在左侧打开,我希望它在右侧打开。我有一个 TextField ( weight=6f) 和 Morevert Icon ( weight=1f) Row。我不明白为什么它从左边打开。谢谢你的帮助。
这是我的代码:
@Composable
fun HistorySearchBar(
text: String,
onTextChange: (String) -> Unit,
onCloseClicked: () -> Unit,
onSearchClicked: (String) -> Unit
) {
val focusRequester = remember { FocusRequester() }
val focus = remember { mutableStateOf(false) }
var showMenu by remember { mutableStateOf(false) }
val inputService = LocalTextInputService.current
Surface(
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
elevation = AppBarDefaults.TopAppBarElevation,
color = MaterialTheme.colors.primary
) {
Row(modifier = Modifier.fillMaxWidth()) { …Run Code Online (Sandbox Code Playgroud)