I have a TextView on each item and added holder.item_edit_text.addTextChangedListener
on onBindViewHolder
for a long list and an interface that computes the total at the fragment level but weirdly when a user types on one view, onBindViewHolder
is called on multiple items.
I.E if a user enters 5, i get multiples of 5 depending on the recycling (number of items in the list) e.g 15 or 25
RECYCLERVIEW onBindViewHolder
holder.item_edit_text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence amount, int start, int before, int count) {
calculateTotal.onAmountAdded(current, amount.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
@Override
public int getItemCount() {
if (Accounts != null) {
return Accounts.size();
}
return 0;
}
Question is how I can ensure that onBindViewHolder
is called for one item in the recyclerview per time
THE FRAGMENT
@Override
public void onAmountAdded(Account account, String amount) {
private Map<Account, String> orderItems = new HashMap<>();
if (amount.length() < 9) {
orderItems.put(account, amount);
int newTotal = 0;
Iterator iterator = orderItems.entrySet().iterator();
while (iterator.hasNext()) {
try {
Map.Entry mentry = (Map.Entry) iterator.next();
newTotal += Integer.parseInt(mentry.getValue().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
text_total.setText(ValidationUtil.formatNumber(String.valueOf(newTotal)));
return;
}
}