hamid20live
جمعه 11 بهمن 1392, 14:13 عصر
لطفا کمک کنید این کد رو چطوری فقط برای یه دکمه بنویسم؟؟؟
@Override
public boolean onTouchEvent(MotionEvent event)
{
boolean[] newButtonStates = new boolean[36];
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;
@Override
public boolean onTouchEvent(MotionEvent event)
{
boolean[] newButtonStates = new boolean[36];
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;