Hai all...

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....

Here is my sub activity to draw on canvas


public class MesureSizeActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.button);
    }
}


and my view class is


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 >= TOUCH_TOLERANCE || dy >= 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

     
     }
 
    }

}

And my xml look like

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        android:visibility="visible"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android";>
        
<com.example.sizemesurment_1.MyView
    android:id="@+id/DrawViewId"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    </com.example.sizemesurment_1.MyView >
    
 <RelativeLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:gravity="bottom">
    
   

    <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" />

    <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" />
    
    
    </RelativeLayout>
</FrameLayout>


While I am pressing the button I got the error like

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'

Am I doing anything wrong..  I am a beginner....
Please help....... 

Thanks in advance.....

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to