开发者

Populating listview from different activities

开发者 https://www.devze.com 2023-03-17 00:34 出处:网络
I have a listview in my activity which is being populated from four different activities. I have an arraylist in each of those four act开发者_StackOverflow中文版ivities. I am passing them into list ac

I have a listview in my activity which is being populated from four different activities. I have an arraylist in each of those four act开发者_StackOverflow中文版ivities. I am passing them into list activity through intent. And in the activity I am trying to populate the listview through them by adding the received arraylists into a single arraylist which populates the listview.

Question:

1) Can I add combine two arraylists into a single one. How can I do so?

2) Do I need to persist data in this case?


I am not sure if there is a Merge function for the arraylist, but you could create a new arraylist which will be your final list.

cycle through your four existing arraylists with a for loop for each of them and add every entry into your final arraylist. while adding new entries into the final arraylist, you could scan it, if the element to be added already exists in it, so you do not have duplicate entrys. the final arraylist could then be sorted.


You DO have to merge them all into one ArrayList, but you can use the ArrayList.add(Collection collection) method. You just have the arraylist from one of the four activities as the parameter and it will add the whole arraylist to the consolidated arraylist.

0

精彩评论

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