可以动态创建小部件吗?

发布于 2025-01-03 20:41:22 字数 100 浏览 0 评论 0原文

对于每个联系人,我想在活动中创建三个复选框和一个 TextView。这可能吗?如果是这样,怎么办?另一个 stackoverflow 答案说不,这是不可能的,但我发现很难相信......

For each Contact, I want to create three checkboxes and a TextView inside an Activity. Is this possible? If so, how? Another stackoverflow answers says No, it's not possible, but I find that hard to believe...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2025-01-10 20:41:22

我不知道为什么这是不可能的。由于它是“针对每个联系人”,我想您需要一个来自 ContactsContract 内容提供商的 Cursor 。因此,如果您的目标是显示联系人列表,您也可能需要 ListView。如果您有一个包含联系人信息的光标,那么您可以利用某种 CursorAdapter 将光标中的这些联系人映射到 ListView 项。然后,您可以使用 3 个 CheckBox 小部件和一个 TextView 设计 ListView 项布局,并适当地填充它们。看来并非不可能。

I don't know why it wouldn't be possible. Since it's "for each contact" I'd imagine you'd want a Cursor from the ContactsContract content provider. As such, you will also likely want a ListView if your goal is to display a list of contacts. Given you have a cursor that has the information for your contact, you'd then utilize a CursorAdapter of some kind to map those contacts in the cursor into ListView items. Then you'd design your ListView item layouts with 3 CheckBox widgets and a TextView and populate them appropriately. Doesn't seem impossible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文