Skip to content

Instantly share code, notes, and snippets.

@RobGThai
Forked from anonymous/refreshListItem.java
Created January 10, 2013 09:33
Show Gist options
  • Save RobGThai/4500764 to your computer and use it in GitHub Desktop.
Save RobGThai/4500764 to your computer and use it in GitHub Desktop.
/**
* Update single item inside {@link ListView}.
* @param target {@link Object} object to update view.
*/
private void refreshListItem(Object target){
ListView list = getListView();
// Find position of the first visible row
int start = list.getFirstVisiblePosition();
// Find position of the last visible row
int end = list.getLastVisiblePosition();
for(int i=start, j=end;i<=j;i++) {
if (target == list.getItemAtPosition(i)) {
// Target view to process
View view = list.getChildAt(i - start);
// Calling getView will redraw the whole item
View v = list.getAdapter().getView(i, view, list);
// Call requestLayout to update only certain item in the view
view.findViewById(R.id.image).requestLayout();
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment