ArrayAdapter:创建 ArrayAdapter 来显示自定义类型的 toString() 方法中的文本的最佳方法是什么?
我打算创建一个保存在自定义对象中的 GPS 坐标的 ArrayList。然后我想显示这些 GPS 坐标的列表。我当前的解决方案是创建一个并行的字符串 ArrayList,本质上是 GPS.toString() 结果。
这似乎是一项复杂的额外工作,可以避免和简化。任何人都可以想出一种更好的方法来做到这一点,而不需要大量的尴尬工作。我研究了一些创建自定义 ArrayAdapter 的方法,但我不确定我是否完全理解如何将 GPS 坐标对象转换为对 ListView 有用的对象。如果您认为这是一个更好的解决方案,您能否深入了解如何正确使用它? (即使它只是一个链接)
提前致谢! 马特
I was going to create an ArrayList of GPS coordinates that are saved in a custom object. I then want to display a list of these GPS coordinates. My current solution is to create a parallel ArrayList of strings that essentially are the GPS.toString() results.
This seems like a complicated bit of extra work that might be able to be avoided and simplified. Can anybody think of a better way to do this that doesn't require an awkwardly large amount of work. I looked a little into creating a custom ArrayAdapter but I'm not sure I fully understand how to convert the GPS coordinate object into something useful for the ListView. If you think this is a better solution, could you perhaps give a little insight into how to use this properly? (even if it's just a link)
Thanks in advance!
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不想沿着这些坐标显示一些奇特的东西,也许您应该坚持使用 GPS.toString() 的 ArrayList 提供的默认 ArrayAdapter。
If you don't want something fancy to show along those coordinates maybe you should stick with the default ArrayAdapter supplied with the ArrayList of your GPS.toString().
为什么不在自定义对象中重写 toString() 方法,然后从数组中迭代它们?
Why don't you override the toString() method in the custom object, then just iterate over them from your array?