get Child View By Position - Android User Interface

Android examples for User Interface:View Child

Description

get Child View By Position

Demo Code


//package com.java2s;

import android.view.View;

import android.widget.AdapterView;

public class Main {
    public static View getChildViewByPosition(int position,
            AdapterView<?> adapterView) {
        final int firstListItemPosition = adapterView
                .getFirstVisiblePosition();
        final int lastListItemPosition = firstListItemPosition
                + adapterView.getChildCount() - 1;

        if (position < firstListItemPosition
                || position > lastListItemPosition) {
            return adapterView.getAdapter().getView(position, null,
                    adapterView);/*w  w w  . ja v  a  2s . c om*/
        } else {
            final int childIndex = position - firstListItemPosition;
            return adapterView.getChildAt(childIndex);
        }
    }
}

Related Tutorials