gpt4 book ai didi

java - 在 do-while 循环中清除列表

转载 作者:行者123 更新时间:2023-12-02 07:28:26 26 4
gpt4 key购买 nike

我正在使用 do-while 循环。在该循环中,我正在进行条件检查,只要条件失败,就必须清除列表。我正在尝试,但没有得到预期的结果。

List<Date> myDateList=new ArrayList<Date>();
int zTmp=0;

do
{
if(condition true)
{
//do task
}else{
myDateList.clear();
//I wish to clear this list when condition fails
}
zTmp++;
}while(zTmp<myList.size());

最佳答案

我想知道如何在ListView上调用clear()。相反,您应该考虑在ListView上设置的Adapter上调用clear()。

下面的代码 fragment 会对您有所帮助。

adapter.clear();
adapter.notifyDataSetChanged();

关于java - 在 do-while 循环中清除列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244698/

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