Android 自定义联系人 ListView 带图标
我正在努力实现上述内容。通过此链接 http://www.pocketmagic.net/?p=1870 ,它几乎显示了我想要实现的目标,除了我想根据条件在联系人的左侧显示一个图标。即如果 Aaron 在 A 公司,则显示 A 公司图标,如果 Betty 在 B 公司,则显示 B 公司图标。问题是联系人数据来自 1 个光标,公司数据来自另一个光标。
我正在查看自定义游标适配器,有没有办法使用来自 2 个游标的数据创建单个游标并将其设置到列表适配器中?这有什么道理。谢谢!
I'm trying to implement the above mentioned. From this link, http://www.pocketmagic.net/?p=1870 , it pretty much shows what I'm trying to achieve, except I want to show an icon on the left side of the contact based on a condition. i.e. If Aaron is in Company A show Company A icon, if Betty is in Company B show Company B icon. Problem is the contacts data is from 1 cursor and the company data is from another cursor.
I'm looking at a custom cursor adapter, is there a way to create a single cursor with data from 2 cursors and set it into the list adapter? How this makes sense. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只有扩展游标适配器,然后在构建视图时截取数据,并使用将要传入的游标数据按照您想要的方式构建它,才能完成此操作。完成此设置后,它就非常容易了。还有一个光标可以将两个光标放在一起..但我不记得这是否是自定义的。
简单的方法是获取数据并将其放入数据结构中,然后从那里处理它。此外,没有规则说您不能将两个光标传递到光标适配器中。让它成为你的! :)
This can only be done if you extend the cursor adapter and then INTERCEPT the data when its building the views and build it how you want it with the cursor data that will be coming in. Once you have this setup its pretty easy. And there is a cursor that can take two cursors and put them together.. but I can't remember if this was custom or not.
Simple way is to just take the data and throw it into a datastructure and then handle it from there. Also there is no rule saying you can't pass in two cursor into your cursor adapter. MAKE IT YOURS! :)
我刚刚回答了一个与此类似的问题,即使用对象列表的 ArrayAdapter。看一下我发布的代码,不要扩展 ArrayAdapter,而是扩展 CursorAdapter(如果您需要使用 Cursor)。或者,您可以构建自定义对象并使用 ArrayAdapter 方法
如何将信息查询放入列表视图中?
另外,这里是 CursorAdapter 的参考:
http://developer.android.com/reference/android/widget/CursorAdapter.html< /a>
希望这有帮助!
I just answered a similar question to this that was to use an ArrayAdapter of an Object list. Take a look at the code I posted and instead of extending ArrayAdapter, extend CursorAdapter (If you need to use a Cursor). Or you can build up a Custom Object and use the ArrayAdapter approach
How to put query of information into a listview?
Also, here's the reference for a CursorAdapter:
http://developer.android.com/reference/android/widget/CursorAdapter.html
Hope this helps!