Passing Multiple Lists into ArrayAdapter

后端 未结 4 1855
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 00:59

I start of with this in Activity:

adapter = new ItemAdapter(Items.this, items, totals);
        setListAdapter(adapter);

Now here is ItemAd

4条回答
  •  不要未来只要你来
    2021-01-17 01:52

    One option you have is to alter the constructor to accept a List> instead of List Then instead of doing this.items = items; you'll have to iterate through all of the subLists in your parameter and add each element to your local object items.

    Another and perhaps more straightforward solution is to merge your mulptiple lists before sending it in to the constructor as a parameter. i.e. you could use a method like List.addAll() like this

    List.addAll(anotherListObject);
    

    as many times as you need to make one List that contains all of your items.

    And yet another option is to use the MergeAdapter that CommonsGuy has created and graciously open sourced to simplify the process by letting you create multiple adapters and then merging them all into one MergeAdapter instead of worrying about merging the Lists

提交回复
热议问题