-1
이 코드는 어떻게 하나의 버튼에만 사용할 수 있습니까? 나는 이것을 바꿀 수 없다!하나의 버튼에만이 코드를 사용할 수 있습니까?
public boolean onTouchEvent(MotionEvent event)
{
boolean[] newButtonStates = new boolean[24];
int action = event.getAction();
boolean isDownAction = (action & 0x36) == 0x36 || action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE;
for (int touchIndex = 0; touchIndex < event.getPointerCount(); touchIndex++)
{
// find button for location
int x = (int) event.getX(touchIndex);
int y = (int) event.getY(touchIndex);
for (int buttonIndex = 0; buttonIndex < buttons.size(); buttonIndex++)
{
View button = buttons.get(buttonIndex);
int[] location = new int[2];
button.getLocationOnScreen(location);
int buttonX = location[0];
int buttonY = location[1];
Rect rect = new Rect(buttonX, buttonY, buttonX + button.getWidth(), buttonY + button.getHeight());
if (rect.contains(x, y))
{
newButtonStates[buttonIndex] = isDownAction;
break;
}
}
}
for (int index = 0; index < newButtonStates.length; index++)
{
if (buttonStates[index] != newButtonStates[index])
{
buttonStates[index] = newButtonStates[index];
View button = buttons.get(index);
toggleButtonSound(button, newButtonStates[index]);
}
}
return true;
? 약간의 설명이 도움이 될 것입니다. –
버튼의 onTouchListener를 구현합니다. – Piyush
화면의 다른 위치에서 버튼을 드래그하여 버튼을 터치하면이 이벤트가 어떻게됩니까? 내게 샘플을주세요. – user3257138