开发者

Binding a ListView to an array of objects

开发者 https://www.devze.com 2023-02-16 05:18 出处:网络
I have an array of Password objects, each containing a tag, a username and a password (all of three S开发者_Go百科trings).

I have an array of Password objects, each containing a tag, a username and a password (all of three S开发者_Go百科trings).

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消