Binding a ListView to an array of objects
I have an array of Password
objects, each containing a tag
, a username
and a password
(all of three S开发者_Go百科tring
s).
I'd like to display the tag
s contained in each Password
in a ListView
.
I thought about using an ArrayAdapter
linked to a String
array containing only the tag
s, but I'm almost sure this would be a bad option as I plan to update frequently the Password
array's contents.
Is there any other option to bind my Password
array to a ListView
and making it display only its tag
attribute?
The simplest solution:
Step #1: Implement toString()
on Password
to return tag
Step #2: Put your Password
objects in an ArrayList<Password>
Step #3: Put your ArrayList<Password>
into an ArrayAdapter<Password>
Step #4: Put your ArrayAdapter<Password>
into your ListView
精彩评论