1

Here is a method I have:

public static void updateRowForReview(int itemRowPosition) {
    adapter.getWasReviewed(itemRowPosition);
    updateReviewAtPosition(itemRowPosition);
}


private static void updateReviewAtPosition(int position) {
    View view = listView.getChildAt(position - listView.getFirstVisiblePosition());
    listView.getAdapter().getView(position, view, listView);

    TextView reviewTotalTV =(TextView) view.findViewById(R.id.tvReviewTotalForItem);
    String reviewTotal = reviewTotalTV.getText().toString();

    int reviewTotalInt = Integer.valueOf(reviewTotal) + 1;
    reviewTotalTV.setText(String.valueOf(reviewTotalInt));
}

No matter what I do, the getText().toString() will only return 1. The TextView tvReviewTotalForItem is dynamic and has all sorts of values in each row of the list. So not sure why it returns this. Is my code wrong?

Also note, the position of the row is correct; it sets the text to the right list row, just the wrong value.

user
  • 86,916
  • 18
  • 197
  • 190
TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259

2 Answers2

1

The problem is most likely due to:

listView.getAdapter().getView(position, view, listView); 

call. As you get the row view directly from the ListView with getChildAt(), it would normally have all the values that you see/want so the getView() call wouldn't be necessary.

user
  • 86,916
  • 18
  • 197
  • 190
0

I am not sure the following would fix your problem, but using a Tag would make it easier to handle. I would replace your code with this one to keep the total in a Tagattached to the TextView:

private static void updateReviewAtPosition(int position) {
    View view = listView.getChildAt(position - listView.getFirstVisiblePosition());
    listView.getAdapter().getView(position, view, listView);

    TextView reviewTotalTV =(TextView) view.findViewById(R.id.tvReviewTotalForItem);
    int reviewTotal = 0;
    if(reviewTotalTV.getTag() != null){
        reviewTotal = (Integer) reviewTotalTV.getTag();
    }

    reviewTotal++;
    reviewTotalTV.setText(String.valueOf(reviewTotal));
    reviewTotalTV.setTag(reviewTotal);
}
Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85