Filters views - Android User Interface

Android examples for User Interface:View

Description

Filters views

Demo Code

/* Athrun - Android automation testing Framework.
 Copyright (C) 2010-2012 TaoBao UI AutoMan Team

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., HuaXing road, Hangzhou,China. 
 Email:taichan@taobao.com,shidun@taobao.com,bingyang.djj@taobao.com
 *//*  www.  j  av  a 2s  .com*/
//package com.java2s;

import java.util.ArrayList;

import android.view.View;

public class Main {
    /**
     * Filters views
     * 
     * @param classToFilterBy
     *            the class to filter
     * @param viewList
     *            the ArrayList to filter form
     * @return an ArrayList with filtered views
     */
    @SuppressWarnings("unchecked")
    public static <T extends View> ArrayList<T> filterViews(
            Class<?> classToFilterBy, ArrayList<View> viewList) {
        ArrayList<T> filteredViews = new ArrayList<T>(viewList.size());
        for (View view : viewList) {
            if (view != null
                    && classToFilterBy.isAssignableFrom(view.getClass())) {
                filteredViews.add((T) view);
            }
        }
        return filteredViews;
    }
}

Related Tutorials