Hi Guys,
I need a helping hand for setOnClickListener.
I have created a Rect class which extends View,
package com.RoboTown;
import android.R.string;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import android.widget.FrameLayout;
public class Rect extends View {
/** Called when the activity is first created. */
private float x;
private float y;
private float z;
private float w;
private String t;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public Rect(Context context, float x, float y, float z, float w,
String t) {
super(context);
mPaint.setColor(0xFFFF0000);
mPaint.setTextSize(20);
this.x = x;
this.y = y;
this.z = z;
this.w = w;
this.t = t;
}
public void setRectX(float x) {
this.x = x;
}
public void setRectY(float y) {
this.y = y;
}
public void setRectZ(float z) {
this.z = z;
}
public void setRectW(float w) {
this.w = w;
}
public void setRectP(int r) {
mPaint.setColor(r);
}
public float getRectX() {
return this.x;
}
public float getRectY() {
return this.y;
}
public float getRectZ() {
return this.z;
}
public float getRectW() {
return this.w;
}
public String getRectT() {
return this.t;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(x, y, z,w, mPaint);
canvas.drawText(t, x+30, y+30, mPaint);
}
}
I ve instanciated an object from Rect class and added it to my main
view (a FrameLayout view) .
final Rect pc1= new Rect(this,60,60,240,240,"");
FrameLayout main = (FrameLayout) findViewById(R.id.main_view);
main.addView(pc1);
pc1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
The problem is that, I have my action done even If I click somewhere
else than pc1 rectangle in my main view...
Do you have an idea please?
Many thanks ^^
--
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
To unsubscribe, reply using "remove me" as the subject.