Looping through ListView twice
I have an activity with a custom ListView. I have two TextViews in each
row, one of them contains static text and the other contains numbers which
are randomly changed on a Button press. I need to save the data of both
TextViews in two seperate ArrayLists (if the value of the number TextView
is not 0). The values are being stored inside the ArrayLists as I wish,
however the records are being inserted twice; such that when I loop
through the ArrayList and show them in a Toast I get twice the value of
the rows entered.
Below are my code snippets:
On Button click adding value of Number TextView
holder.add.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
int temp = numPickerValues.get(position);
temp += 1;
numPickerValues.set(position, temp);
notifyDataSetChanged();
}
});
holder.num.setText(String.valueOf(numPickerValues.get(position)));
Adding values of non-0 TextViews to ArrayList
if(!holder.num.getText().equals("0"))
{
materialNames.add(holder.txt.getText().toString());
materialAmounts.add(holder.num.getText().toString());
}
This is the fun part. I debugged the application to check where the
problem lies and I found out it is looping inside the ListView twice and
thus storing the values twice inside the ArrayLists, however I do not have
the values duplicated in my ListView. The duplicated value of one TextView
is being shown after another, so it is not exactly looping twice,
otherwise the values would be separated by others.
Any idea of what is going on?
No comments:
Post a Comment