将ArrayAdapter转换为List <String>

jcw*_*jcw 1 android arraylist android-arrayadapter

我有一个数组适配器(字符串),并希望将其转换为a List<String>,但经过一些谷歌搜索和一些尝试后,我不知道如何做到这一点.

我试过以下几点;

for(int i = 0; i < adapter./*what?*/; i++){
     //get each item and add it to the list
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为似乎没有adapter.lengthadapter.size()方法或变量.

然后我尝试了这种类型的for循环

for (String s: adapter){
    //add s to the list
}
Run Code Online (Sandbox Code Playgroud)

但是适配器不能在foreach循环中使用.

然后我做了一些谷歌搜索方法(在数组中)从适配器转换为列表,但没有找到任何东西.

做这个的最好方式是什么?它甚至可能吗?

小智 5

for(int i = 0; i < adapter.getCount(); i++){
     String str = (String)adapter.getItem(i);
}
Run Code Online (Sandbox Code Playgroud)