I have an imageView with some listeners, such as onClickListener and onLongClickListener. The onLongClickListener responds by adding an onTouchListener to the same view, to listen for motion events. The purpose of this is that when user long clicks on the button, he can then resize it.
The imageView resizing works (not very well, but enough for testing), but, after resizing, all the listeners attached to the view only respond to touches in the area covered by the original dimensions of the imageView. So if user stretches the button downwards to double its height, only the top half will respond to click and touch events.
So do I have to either;
detach and re-attach all of the listeners?
update the listeners somehow?
Here is my code
sendButton = (ImageView) findViewById(R.id.sendButton);
sendButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.d("long click", "long click");
v.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
int currentY = 0;
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
currentY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
if (event.getY() > currentY) {
Log.d("y dir", String.valueOf(event.getY()));
ViewGroup.LayoutParams params = buttonSpace
.getLayoutParams();
params.height++;
buttonSpace.setLayoutParams(params);
} else if (event.getY() < currentY) {
Log.d("y dir", "up");
ViewGroup.LayoutParams params = buttonSpace
.getLayoutParams();
params.height--;
buttonSpace.setLayoutParams(params);
}
currentY = (int) event.getY();
break;
}
return false;
}
});
return true;
}
});
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendButtonPressed();
}
});