gpt4 book ai didi

安卓架构组件 : Multiple instances of the same view model

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:51:14 25 4
gpt4 key购买 nike

我是 Android 架构组件的新手,我已阅读 this教程。我对它所说的部分感兴趣:

This allows you to have an app that opens a lot of different instances of the same Activity or Fragment, but with different ViewModel information. Let’s imagine if we extended our Court-Counter example to have the scores for multiple basketball games. The games are presented in a list, and then clicking on a game in the list opens a screen that looks like our current MainActivity, but which I’ll call GameScoreActivity.

假设我有一个 ViewModel MyViewModel。我想创建这个 View 模型的列表,但直到运行时我才知道这个列表中的元素数量。在 for 循环中创建 View 模型实例方便吗?我可以创建多少个实例?实例数会影响性能吗?

最佳答案

ViewModel 提供程序采用可选的,您可以使用它来区分 ViewModel 实例。

关于安卓架构组件 : Multiple instances of the same view model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48519543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com