可以动态创建小部件吗?
对于每个联系人,我想在活动中创建三个复选框和一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么这是不可能的。由于它是“针对每个联系人”,我想您需要一个来自
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 theContactsContract
content provider. As such, you will also likely want aListView
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 aCursorAdapter
of some kind to map those contacts in the cursor intoListView
items. Then you'd design yourListView
item layouts with 3CheckBox
widgets and aTextView
and populate them appropriately. Doesn't seem impossible.