Reputation: 97
while(iter.hasNext()) iterator has items but condition doesn't work. What's wrong there?
iter= productDataList.iterator();
public void CalcPrice(View v){
while(iter.hasNext()){
if(iter.next().name.equals(pName)){
price=Integer.parseInt(iter.next().price);
}
}
edPrice.setText("Tutar : "+price);
}
Upvotes: 1
Views: 143
Reputation: 78985
The problem is that you are calling iter.next()
twice for the same data.
Do it as follows:
iter= productDataList.iterator();
public void CalcPrice(View v){
while(iter.hasNext()){
Product productData = iter.next()
if(productData.name.equals(pName)){
price=Integer.parseInt(productData.price);
break;
}
}
edPrice.setText("Tutar : "+price);
}
Upvotes: 3