Get Adapter View from View - Android User Interface

Android examples for User Interface:AdapterView

Description

Get Adapter View from View

Demo Code


//package com.java2s;
import android.util.SparseArray;
import android.view.View;

public class Main {

    @SuppressWarnings("unchecked")
    public static <T extends View> T getAdapterView(View convertView, int id) {
        SparseArray<View> viewHolder = (SparseArray<View>) convertView
                .getTag();/*from  w  w w . j  a  va  2 s.  c o  m*/
        if (viewHolder == null) {
            viewHolder = new SparseArray<View>();
            convertView.setTag(viewHolder);
        }
        View childView = viewHolder.get(id);
        if (childView == null) {
            childView = convertView.findViewById(id);
            viewHolder.put(id, childView);
        }
        return (T) childView;
    }
}

Related Tutorials