set On click Listener On View With Id - Android User Interface

Android examples for User Interface:View Click

Description

set On click Listener On View With Id

Demo Code

/*/*from  ww w  . j a  va 2s.  c o  m*/
 * *
 *  * 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;
import android.view.ViewGroup;

public class Main {
    public static void setOnclikListenerOnViewWithId(View view,
            OnClickListener listener) {
        if (view == null) {
            return;
        }
        if (view.getId() != View.NO_ID) {
            view.setOnClickListener(listener);
        }
        if (view instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) view;
            for (int i = 0; i < group.getChildCount(); ++i) {
                setOnclikListenerOnViewWithId(group.getChildAt(i), listener);
            }
        }
    }
}

Related Tutorials