set On Click Listener by view ID - Android User Interface

Android examples for User Interface:View Click

Description

set On Click Listener by view ID

Demo Code


import android.app.Activity;
import android.view.View;

public class Main {
  public static View setOnClickListener(Activity activity, int viewId,
      View.OnClickListener onClickListener) {
    return setOnClickListener(activity.findViewById(viewId), onClickListener);
  }// ww  w. j a v a 2  s .  c  om

  public static View setOnClickListener(View v, int viewId,
      View.OnClickListener onClickListener) {
    return setOnClickListener(v.findViewById(viewId), onClickListener);
  }

  public static View setOnClickListener(View v,
      View.OnClickListener onClickListener) {
    v.setOnClickListener(onClickListener);
    return v;
  }
}

Related Tutorials