Add On Long Click Binder to View recursively - Android User Interface

Android examples for User Interface:View Click

Description

Add On Long Click Binder to View recursively

Demo Code


//package com.java2s;

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

public class Main {
    public static void deepOnLongClickBinder(View view,
            View.OnLongClickListener listener) {
        if (view == null) {
            return;
        }//from   www. j a  v  a 2 s  . c  o m
        view.setOnLongClickListener(listener);
        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); ++i) {
                View v = ((ViewGroup) view).getChildAt(i);
                if (v instanceof ViewGroup) {
                    deepOnLongClickBinder(v, listener);
                } else {
                    v.setOnLongClickListener(listener);
                }
            }
        }

    }
}

Related Tutorials