在一次多点触控的onClick多个按钮 [英] onClick Multiple Buttons at once multitouch
问题描述
林编写一个小游戏,两个玩家必须点击一些按钮它的工作原理pretty的好,如果只有一名球员,但是当其他球员也打了他本场比赛的一部分,那么该按钮不做任何事情。
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.
我怎样才能使多点触控,这样2按钮可以一次获得点击?
How can i enable Multitouch so that 2 Buttons can get clicked at once ?
编辑: 下面是一些code:
Here is some Code:
布局XML
Layout XML
<ImageButton
android:id="@+id/game1_player2"
[...]
android:background="@android:color/transparent"
android:src="@drawable/player2_countdown_1"
android:onClick="player2method"/>
INY我的Java扩展了活动文件:
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();
}
}
如果玩家1点击他的按键一切都很好,但如果其他球员也没有点击按钮被激活:(
If Player one clicks his buttons all is fine but if the other player also clicks no button is activated :(
推荐答案
<一个href="http://stackoverflow.com/questions/2753659/click-two-buttons-at-the-same-time-in-android">Click在同一时间在机器人的两个按钮
所以从第一个发布链接好像你需要重写触摸事件不只是的onclick
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
如果没有这些帮助,请张贴一些code
if neither of these help, please post some code
几个因以下
<一个href="http://stackoverflow.com/questions/5928972/android-multitouch-action-up-not-always-called">Android多点触控:ACTION_UP并不总是叫
这篇关于在一次多点触控的onClick多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!