how to get all elements of an ArrayAdapter?
Asked Answered
R

2

14

I need get all elements of ArrayAdapter of an ListView.

Like this:

    this.array = new ArrayAdapter<DocumentoDominiabilidade>(getActivity(),
            android.R.layout.simple_list_item_1);
    this.documentosDominiabilidade.setAdapter(array);

// after many operations

this.array.getAllElements() // return a List of Elements????

thank you

Ruhr answered 17/7, 2013 at 22:52 Comment(0)
M
42

Using Adapter.getCount() you can know how many items you have in the adapter, while using Adapter.getItem(index) will give you the item.

for(int i=0 ; i<adapter.getCount() ; i++){
   Object obj = adapter.getItem(i);
}
Monica answered 17/7, 2013 at 22:57 Comment(0)
G
0

Based on JafarKhQ's answer, here's a one-liner to put them all into a List:

IntStream
    .range(0, adapter.getCount())
    .mapToObj(adapter::getItem)
    .collect(Collectors.toList());
Gyrfalcon answered 28/5, 2021 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.