In every activity in my app, the users are able to press two button at the same time. How can I prevent they to do this?
在我的应用中的每个活动中,用户都可以同时按下两个按钮。我怎么能阻止他们这样做?
8 个解决方案
#1
4
you can disable the multi touch in the screen...which can allow only single touch by
您可以在屏幕中禁用多点触控...这样只允许单次触摸
place this line button viewGroup layout
放置此行按钮viewGroup布局
android:splitMotionEvents="false"
机器人:splitMotionEvents = “假”
<LinearLayout
android:id="@+id/list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:splitMotionEvents="false" >
<Button
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none" >
</Button>
<Button
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none" >
</Button>
</LinearLayout>
#2
1
You can try like this :
你可以尝试这样:
findViewById(R.id.buttonX).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ViewGroup group = (ViewGroup)findViewById(R.id.container);
for (View touchable : group.getTouchables()) {
if (touchable != view && touchable.isPressed()) {
Log.d("...", "skip");
}
}
}
});
#3
0
Disable all other buttons on click listener of all buttons
禁用所有按钮的单击侦听器上的所有其他按钮
#4
0
On First button click, you can do this for particular seconds by running one thread
在第一个按钮单击时,您可以通过运行一个线程在特定秒内执行此操作
second_btn.setEnabled(false); or second_btn.setClickable(false);
#5
0
If the buttons are one near other you can make a radiogroup that do your job without any work:D. If not you can use a synk boolean variable and play witt all the cases.
如果按钮是一个接近另一个按钮,你可以制作一个无需任何工作就能完成工作的无线电组:D。如果不是,您可以使用synk布尔变量并播放所有情况。
#6
0
A radio group should do the magic. As the user will be able to select any one option(i mean the button at a time).
一个广播组应该发挥魔力。因为用户将能够选择任何一个选项(我的意思是一次按钮)。
#7
0
You could try something like this for every single button:
您可以为每个按钮尝试这样的事情:
boolean buttonClicked = false;
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!buttonClicked) {
buttonClicked = true;
...
...
...
buttonClicked = false;
}
}
});
#8
0
To disable press two button at the same time multi-touch on your app by using this approach in your theme - it works fine!
要在您的主题中使用此方法同时禁用同时按下两个按钮 - 它工作正常!
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:splitMotionEvents">false</item>
<item name="android:windowEnableSplitTouch">false</item>
</style>
#1
4
you can disable the multi touch in the screen...which can allow only single touch by
您可以在屏幕中禁用多点触控...这样只允许单次触摸
place this line button viewGroup layout
放置此行按钮viewGroup布局
android:splitMotionEvents="false"
机器人:splitMotionEvents = “假”
<LinearLayout
android:id="@+id/list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:splitMotionEvents="false" >
<Button
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none" >
</Button>
<Button
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none" >
</Button>
</LinearLayout>
#2
1
You can try like this :
你可以尝试这样:
findViewById(R.id.buttonX).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ViewGroup group = (ViewGroup)findViewById(R.id.container);
for (View touchable : group.getTouchables()) {
if (touchable != view && touchable.isPressed()) {
Log.d("...", "skip");
}
}
}
});
#3
0
Disable all other buttons on click listener of all buttons
禁用所有按钮的单击侦听器上的所有其他按钮
#4
0
On First button click, you can do this for particular seconds by running one thread
在第一个按钮单击时,您可以通过运行一个线程在特定秒内执行此操作
second_btn.setEnabled(false); or second_btn.setClickable(false);
#5
0
If the buttons are one near other you can make a radiogroup that do your job without any work:D. If not you can use a synk boolean variable and play witt all the cases.
如果按钮是一个接近另一个按钮,你可以制作一个无需任何工作就能完成工作的无线电组:D。如果不是,您可以使用synk布尔变量并播放所有情况。
#6
0
A radio group should do the magic. As the user will be able to select any one option(i mean the button at a time).
一个广播组应该发挥魔力。因为用户将能够选择任何一个选项(我的意思是一次按钮)。
#7
0
You could try something like this for every single button:
您可以为每个按钮尝试这样的事情:
boolean buttonClicked = false;
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!buttonClicked) {
buttonClicked = true;
...
...
...
buttonClicked = false;
}
}
});
#8
0
To disable press two button at the same time multi-touch on your app by using this approach in your theme - it works fine!
要在您的主题中使用此方法同时禁用同时按下两个按钮 - 它工作正常!
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:splitMotionEvents">false</item>
<item name="android:windowEnableSplitTouch">false</item>
</style>