set Child View On Click Listener - Android User Interface

Android examples for User Interface:View Child

Description

set Child View On Click Listener

Demo Code

/*//  ww  w  .j a  v  a  2  s .  com
 * *
 *  * Copyright 2012 fenbi.com. All rights reserved.
 *  * FENBI.COM PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */
//package com.java2s;

import android.view.View;
import android.view.View.OnClickListener;

public class Main {
    public static View setChildOnClickListener(View parent, int cid,
            OnClickListener listener) {
        if (parent != null) {
            View v = parent.findViewById(cid);
            if (v != null) {
                v.setOnClickListener(listener);
            }
            return v;
        }
        return null;
    }

    public static void setChildOnClickListener(View parent, int[] cids,
            OnClickListener listener) {
        if (parent != null && cids != null) {
            for (int cid : cids) {
                View v = parent.findViewById(cid);
                if (v != null) {
                    v.setOnClickListener(listener);
                }
            }
        }
    }
}

Related Tutorials