i've searched around and still can't find a good answer. I have made my own class that extends an imageView and in the onDraw() method i am using canvas to draw circles onto my image.
What i want to do now though is draw a button onto the image in different places and have an onClick event for it, so when the user presses the button it will open up a new activity..
Here is what I have so far..It draws the buttons in the right locations except my onClick method isn't firing
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
//1.arrayList Points. 2.arrayLists for points in X, 3.arrayList for points in Y
for(int i=0; i<arrayListPoints.size(); i++){
Button b = new Button(mContext);
LinearLayout ll = new LinearLayout(mContext);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(alPoints_x.get(i), alPoints_y.get(i), 0, 0);
ll.addView(b, layoutParams);
//Measure and layout the linear layout before drawing it
ll.measure(MeasureSpec.getSize(ll.getMeasuredWidth()), MeasureSpec.getSize(ll.getMeasuredHeight()));
ll.layout(0, 0, MeasureSpec.getSize(b.getMeasuredWidth()), MeasureSpec.getSize(b.getMeasuredHeight()));
//Finally draw the linear layout on the canvas
ll.draw(canvas);
//create an onClick event for the button
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast msg = Toast.makeText(mContext, "button clicked \n", Toast.LENGTH_LONG);
msg.show();
} //end of public void
});
}
invalidate();
} //end of onDraw()