Federico klez Culloca
Federico klez Culloca

Reputation: 27119

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 Strings).

I'd like to display the tags contained in each Password in a ListView.

I thought about using an ArrayAdapter linked to a String array containing only the tags, 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?

Upvotes: 1

Views: 1492

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

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

Upvotes: 3

Related Questions