Skip to content

Instantly share code, notes, and snippets.

@fnzainal
Created January 13, 2017 01:47
Show Gist options
  • Save fnzainal/90be8f39295e04fadfe2b007ffa38a90 to your computer and use it in GitHub Desktop.
Save fnzainal/90be8f39295e04fadfe2b007ffa38a90 to your computer and use it in GitHub Desktop.
untuk mengambil View pada item listview
/**
* untuk mencari posisi item pada listview
* @param position : posisi item pada listview
* @param listView : listview
* @return View posisi item
*/
public static View getViewByPosition(int position, ListView listView) {
final int firstListItemPosition = listView.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition
+ listView.getChildCount() - 1;
if (position < firstListItemPosition || position > lastListItemPosition) {
return listView.getAdapter().getView(position, null, listView);
} else {
final int childIndex = position - firstListItemPosition;
return listView.getChildAt(childIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment