OnClickListener on View class
<p>Can any one tell me how to crate an onclicklistenr inside a view class.. </p>

<p>I created an application like drawing on canvas by taking image from camera.. I created some custom button using frame layout inside  my view class.. But I am not able to create an onclicklistener inside view class....</p>

<p>Here is my sub activity to draw on canvas</p>

<pre><code> public class MesureSizeActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.button);
     }
    }
</code></pre>

<p>and my view class is</p>

<pre><code>public class MyView extends View {



private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
private Paint mPaint;
boolean calibrate=true;
int calibrate_x;
int calibrate_y;
int calibrate_radius;

//Event listener controller

boolean listener_calibrate= true;

public MyView(Context c) {
    super(c);
    mBitmap = MainActivity.getBitmap();
    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(0xFFFFFF11);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    // mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);
}

public MyView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mBitmap = MainActivity.getBitmap();
    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(0xFFFFFF11);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    // mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);
}

public MyView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}


@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mBitmap = Bitmap.createScaledBitmap(mBitmap, w, h, true);
    mCanvas = new Canvas(mBitmap);
    calibrate_x = w /2;
    calibrate_y = h/2;
    calibrate_radius = 50;

}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawColor(0xFFAAAAAA);

    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

      canvas.drawCircle(calibrate_x,calibrate_y,calibrate_radius,mPaint);
    canvas.drawPath(mPath, mPaint);

}

private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;

private void touch_start(float x, float y) {
    mPath.reset();
    mPath.moveTo(x, y);
    mX = x;
    mY = y;
}

private void touch_move(float x, float y) {
    float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx &gt;= TOUCH_TOLERANCE || dy &gt;= TOUCH_TOLERANCE) {
        // mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
        mX = x;
        mY = y;
    }
}

private void touch_up() {
    mPath.lineTo(mX, mY);
    // commit the path to our offscreen
    mCanvas.drawPath(mPath, mPaint);
    // kill this so we don't double draw
    mPath.reset();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        touch_start(x, y);
        invalidate();
        break;
    case MotionEvent.ACTION_MOVE:
        touch_move(x, y);
        invalidate();
        break;
    case MotionEvent.ACTION_UP:
        touch_up();

        invalidate();
        break;
    }
    return true;
  }

 public void onClick(View v) {

  if(v.getId() == R.id.up)
  {
    //Do some thing


  }

 if(v.getId() == R.id.down)
 {
    //Do some thing


  }

 }

 }
</code></pre>

<p>And my xml look like</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;FrameLayout
        android:visibility="visible"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"&gt;

&lt;com.example.sizemesurment_1.MyView
    android:id="@+id/DrawViewId"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;
    &lt;/com.example.sizemesurment_1.MyView &gt;

 &lt;RelativeLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:gravity="bottom"&gt;



    &lt;ImageButton
        android:id="@+id/up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="80dp"
         android:onClick="ButtonOnClick"          
        android:src="@drawable/up" /&gt;

    &lt;ImageButton
        android:id="@+id/down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="120dp"  
        android:onClick="ButtonOnClick"    
        android:src="@drawable/down" /&gt;


    &lt;/RelativeLayout&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>While I am pressing the button I got the error like</p>

<p>Could not find a method ButtonOnClick(View) in the activity class com.example.sizemesurment_1.MesureSizeActivity for onClick handler on view class android.widget.Button with id 'up'</p>

<p>Am I doing anything wrong..  I am a beginner....
Please help.......</p>

<p>Thanks in advance.....</p>
