Performs a depth-first search for Views contained in the given view, and returns all views that match the given filter. - Android User Interface

Android examples for User Interface:View

Description

Performs a depth-first search for Views contained in the given view, and returns all views that match the given filter.

Demo Code


import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextWatcher;
import android.text.format.Time;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnFocusChangeListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

public class Main{
    /**/* w ww.j  a v a 2s .  c o m*/
     * Performs a depth-first search for Views contained in the given view, and returns
     * all views that match the given filter. Can be used to perform operations on the child
     * views directly by putting the operation in the ViewFilter's matches() method
     * @param v the root view.
     * @param viewList views that match the filter are added to this list.
     * @param filter specifies the search criteria for the search.
     * @return the given list, populated with matching views.
     */
    public static List<View> getChildren(View v, List<View> viewList,
            ViewFilter filter) {

        if (v instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) v;
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                getChildren(viewGroup.getChildAt(i), viewList, filter);
            }
        }

        if (filter.matches(v)) {
            viewList.add(v);
        }
        return viewList;
    }
}

Related Tutorials