gpt4 book ai didi

android - 将 ArrayAdapter 转换为 List

转载 作者:行者123 更新时间:2023-11-29 14:38:57 27 4
gpt4 key购买 nike

我有一个数组适配器(字符串),想将其转换为 List<String> ,但经过一些谷歌搜索和几次尝试后,我并没有更接近于弄清楚如何做到这一点。

我尝试了以下;

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

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

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

for (String s: adapter){
//add s to the list
}

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

然后我在谷歌上搜索了一个从适配器转换为列表的方法(在数组中),但一无所获。

最好的方法是什么?有可能吗?

最佳答案

for(int i = 0; i < adapter.getCount(); i++){
String str = (String)adapter.getItem(i);
}

关于android - 将 ArrayAdapter 转换为 List<String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18748116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com