gpt4 book ai didi

java - 为什么listInterator.hasNext()总是返回true?

转载 作者:行者123 更新时间:2023-12-01 14:02:37 25 4
gpt4 key购买 nike

我有一个 listInterator,其中只有一个元素。我有一个函数需要知道它有下一个元素的 id。但 hasNext() 方法始终返回 true。

此代码位于按钮的 oncliclistener 内。我只想:当用户单击此按钮时,如果有下一个元素,则更改某些图像,如果没有更改为另一个图像。

    ListIterator<String> lInterator = datas.listIterator(datas.size() - 1);

if(lInterator.hasNext()){
imgDataProxima.setBackgroundResource(R.drawable.bt_next);
} else {
imgDataProxima.setBackgroundResource(R.drawable.btcheckin_next_disabled);
}

if(lInterator.hasPrevious()){
imgDataAnterior.setBackgroundResource(R.drawable.bt_previous);
} else {
imgDataAnterior.setBackgroundResource(R.drawable.btcheckin_previous_disabled);
}

在我的测试中,我仅使用数组中的一个元素。 hasPreviuos() 工作正常。但即使数组中只有一个元素,hasNext() 也会返回 true。

最佳答案

您必须实现lInterator.next()才能转发光标。

if(lInterator.hasNext()){
imgDataProxima.setBackgroundResource(R.drawable.bt_next);
lInterator.next(); // add this row
} else {
imgDataProxima.setBackgroundResource(R.drawable.btcheckin_next_disabled);
}

if(lInterator.hasPrevious()){
imgDataAnterior.setBackgroundResource(R.drawable.bt_previous);
} else {
imgDataAnterior.setBackgroundResource(R.drawable.btcheckin_previous_disabled);
}

关于java - 为什么listInterator.hasNext()总是返回true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19232047/

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