register Views on click listener - Android User Interface

Android examples for User Interface:View Click

Description

register Views on click listener

Demo Code


//package com.java2s;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;

public class Main {
    public static void registerViews(Activity act,
            OnClickListener listener, int... ids) {
        for (int id : ids) {
            View v = act.findViewById(id);
            if (null != v)
                v.setOnClickListener(listener);
        }/*  w w w. j  a  va 2  s  .  c o m*/
    }

    public static void registerViews(Activity act,
            OnClickListener listener, View... views) {
        for (View v : views) {
            v.setOnClickListener(listener);
        }
    }
}

Related Tutorials