ArrayAdapter: What is the best way to approach creating an ArrayAdapter that would display the text from the toString() method of a custom type?
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.
开发者_Go百科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
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().
Why don't you override the toString() method in the custom object, then just iterate over them from your array?
@Override
public String toString() {
return "Latitude: " + this.latitude; //....;
}
精彩评论