-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 for按鈕。 – Piyush
如果我用手指觸摸按鈕從其他位置的屏幕按鈕這個事件是什麼?請給我一個樣品 – user3257138