Call this view's and this view's child's OnClickListener, if it is defined. - Android User Interface

Android examples for User Interface:View Child

Description

Call this view's and this view's child's OnClickListener, if it is defined.

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    /**//from ww  w  .j  a v a 2s.c om
     * Call this view's and this view's child's OnClickListener, <br>
     * if it is defined. <br>
     * Performs all normal actions associated with clicking: <br>
     * reporting accessibility event, playing a sound, etc.
     * 
     * @param view
     * @return True there was an assigned OnClickListener that was called, false
     *         otherwise is returned.
     */
    public static boolean performClick(View view) {
        if (view == null)
            return false;
        boolean result = view.performClick();
        if (!result && (view instanceof ViewGroup)) {
            int count = ((ViewGroup) view).getChildCount();
            for (int i = 0; i < count; i++) {
                result = ((ViewGroup) view).getChildAt(i).performClick();
                if (result)
                    break;
            }
        }
        return result;
    }
}

Related Tutorials