get View By Position - Android android.view

Android examples for android.view:View

Description

get View By Position

Demo Code

import android.view.View;
import android.widget.ListView;

public class Main {

  public static View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition) {
      return listView.getAdapter().getView(pos, null, listView);
    } else {/* www .  j a va2 s  .  c  om*/
      final int childIndex = pos - firstListItemPosition;
      return listView.getChildAt(childIndex);
    }
  }

}

Related Tutorials