I have a custom button, on which I am capturing its onTouchEvent.
public class CustomNumber extends ToggleButton {
boolean drawGlow = false;
float glowX = 0;
float glowY = 0;
float radius = 30;
public CustomNumber(Context context) {
super(context);
}
public CustomNumber(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomNumber(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
Paint paint = new Paint();
{
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setAlpha(70);
};
@Override
public void draw(Canvas canvas){
super.draw(canvas);
if(drawGlow)
canvas.drawCircle(glowX, glowY, radius, paint);
}
@Override
**public boolean onTouchEvent(MotionEvent event)**{
if(event.getAction() == MotionEvent.ACTION_DOWN){
drawGlow = true;
}else if(event.getAction() == MotionEvent.ACTION_UP)
drawGlow = false;
glowX = event.getX();
glowY = event.getY();
this.invalidate();
return true;
}
}
This custom button is the part of a grid. When I am adding this button to the grid, I have set a OnClickListener to it. But, the code in the OnClickListener is never invoked.
//Grid Adapter code, where I am adding the button with listener.
public View getView(final int position, final View convertView, final ViewGroup parent) {
CustomNumber tBtn;
if (convertView == null) {
tBtn = new CustomNumber(context);
tBtn.setTextOff("");
tBtn.setTextOn("");
tBtn.setChecked(false);
tBtn.setId(position);
tBtn.setOnClickListener(tBtnListener);
tBtn.setLayoutParams(new GridView.LayoutParams(35, 35));
} else {
tBtn = (CustomNumber) convertView;
}
return tBtn;
}
Please help.