0

Im programming a little game where two Players have to click some Buttons it works pretty good if there is only one player, but when the other player is also playing his part of the game then the Buttons dont do anything.

How can i enable Multitouch so that 2 Buttons can get clicked at once ?

EDIT: Here is some Code:

Layout XML

<ImageButton
    android:id="@+id/game1_player2"
    [...]
    android:background="@android:color/transparent"
    android:src="@drawable/player2_countdown_1" 
    android:onClick="player2method"/>

Iny My Java extends activity File:

public void player1method (View v)
{
    if(buttonzahl == player2_nextbutton)
    {
        Toast.makeText(getApplicationContext(), "player1 won", Toast.LENGTH_LONG).show();
    }
    else
    {
        Toast.makeText(getApplicationContext(), "player2 won", Toast.LENGTH_LONG).show();
    }
}

public void player2method(View v)
{
    if(buttonzahl == player2_nextbutton)
    {
        Toast.makeText(getApplicationContext(), "player2 won", Toast.LENGTH_LONG).show();
    }
    else
    {
        Toast.makeText(getApplicationContext(), "player1 won", Toast.LENGTH_LONG).show();
    }
}

If Player one clicks his buttons all is fine but if the other player also clicks no button is activated :(

Jonathan
  • 516
  • 5
  • 20

2 Answers2

3

Multiple button presses for Android 2.x

Click two buttons at the same time in Android

so from the first posted link it seems like you need to override the touch events not just the onclick

the second post talks about versions

if neither of these help, please post some code

few more links due to comments below

Android multitouch: ACTION_UP not always called?

Android - OnTouch Do Work

getAction() gives only ACTION_DOWN

Community
  • 1
  • 1
owen gerig
  • 6,165
  • 6
  • 52
  • 91
  • The links only describe how to make multitouch gestures like pinch to zoom but i just want to activate two Buttons at the same time :/ – Jonathan Jan 03 '12 at 22:17
  • right but from what im understanding is that multi touch is just that and onclick is not part of that. you have to use the gestures to get the multitouch – owen gerig Jan 04 '12 at 14:24
  • I have it work now with OnTouchEvent but when the second player touches at the same time with the player 1 the Motionevent ACTION_DOWN is not called, which is the right Motionevent for multiple Touches ? – Jonathan Jan 05 '12 at 20:09
1

You can do it easily by running a separate thread that would listen to TouchEvents and Updates the UI with the help of Handler. Since your UI is never stuck and background thread will always listen for simultaneous touch events.

Amritpal Singh
  • 984
  • 2
  • 14
  • 33