如何在 Android 的芯片组中显示所选的芯片?

huangapple go评论84阅读模式
英文:

How can i show the selected chips in chip group android

问题

我正在开发一个物业列表应用程序,用户可以列出他们的房间等物业。现在我面临的问题是在"更新列表详情"部分。基本上,我们有四个片段,用户通过这些片段填写他们的物业详情,最后将其发布到我们的平台上。现在,当用户想要更改他们的物业列表详情时,用户必须通过相同的四个片段来更新他们的物业详情。在这里,我遇到的问题是,当用户点击"更新列表按钮"时,第一个片段会打开,其中包含用户在列出他们的物业时之前选择的芯片组,现在我希望芯片组应该显示用户在列出他们的物业时选择的芯片。我不知道该如何做到这一点,请指导我。

这是列出物业的第一个片段的图片,如我们所见,它不显示用户在列出物业时选择的芯片:
如何在 Android 的芯片组中显示所选的芯片?

英文:

I am working on an property listing application where users can list their property like rooms etc. Now the problem I m facing is in the "update listing details" part. So basically we have four fragments through that user fill their property details and then finally it got posted on our platform. Now when user wants to make any changes in their property listing details user have to go through the same four fragments to update the details of their property. Here i m facing the problem when user clicks the update listing button the first fragment opens with chip groups which user selected before during listing their property now I want that the chip groups should show the selected chips which user selected while listing their property. I have no idea how can i do this. Please guide me.

Here The Image of first fragment in listing property as we can see that this does not show selected chips which user selected during listing property
如何在 Android 的芯片组中显示所选的芯片?

答案1

得分: 1

从托管片段的活动中获取共享的 ViewModel 数据,将其作为生命周期所有者。

例如:val ViewModel: MainActivityViewModel by activityViewModels

然后设置第一个片段以观察所选属性。
由于数据的来源保持不变,您可以操作如何从中显示所选项目。

英文:

Take the data from a shared ViewModel with the Activity which houses the fragments as a lifecycle owner.

eg: val ViewModel:MainActivityViewModel by activityViewModels

Then set the first fragment to observe the selected properties .
Since the source of your data remains the same you can manipulate how to show the selected items from there

huangapple
  • 本文由 发表于 2023年2月27日 11:00:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定