How to access child views from a ListView in android

Are you get lots problems during access child view from a listview in android, then here is the some solution that may helpful for you.



Android ListView: get data index of visible itemand combine with part of Feet's answer above, can give you something like:

int wantedPosition = 10; // Whatever position you're looking for
int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); // This is the same as child #0
int wantedChild = wantedPosition - firstPosition;
// Say, first visible position is 8, you want position 10, wantedChild will now be 2
// So that means your view is child #2 in the ViewGroup:
if (wantedChild < 0 || wantedChild >= listView.getChildCount()) {
Log.w(TAG, "Unable to get view for desired position, because it's not being displayed on screen.");
return;
}
// Could also check if wantedPosition is between listView.getFirstVisiblePosition() and listView.getLastVisiblePosition() instead.
View wantedView = listView.getChildAt(wantedChild);

this solution copy from stackoverflow and i solved my solution from this:

Happy Coding!!!
How to access child views from a ListView in android How to access child views from a ListView in android Reviewed by D Kshetri on 11:13 AM Rating: 5

No comments:

Powered by Blogger.