Is there a way to only register a single button press? At the moment in my activity I have two buttons that each start another activity - at the moment if I press them at the same time both activities start, one over the other. I want to prevent this and only have one OR the other running at any given time. I thought about disabling multitouch but that feels kind of hacky to me.
EDIT: I've tried to do this:
public class MainActivity extends Activity {
Button btn_send;
Button btn_receive;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_send = (Button) findViewById(R.id.btn_send);
btn_receive = (Button) findViewById(R.id.btn_receive);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
if (v.equals(btn_send)) {
if (isWifiConnected()) {
btn_receive.setClickable(false);
startActivity(new Intent(MainActivity.this,
SendActivity.class));
} else {
Toast.makeText(MainActivity.this,
"Wifi connection required", Toast.LENGTH_SHORT)
.show();
}
} else if (v.equals(btn_receive)) {
if (isWifiConnected()) {
btn_send.setClickable(false);
startActivity(new Intent(MainActivity.this,
ReceiveActivity.class));
} else {
Toast.makeText(MainActivity.this,
"Wifi connection required", Toast.LENGTH_SHORT)
.show();
}
}
}
};
btn_send.setOnClickListener(listener);
btn_receive.setOnClickListener(listener);
}
@Override
public void onPause() {
btn_send.setClickable(true);
btn_receive.setClickable(true);
super.onPause();
}
}
I can still press both buttons at the same time on my Galaxy S2 GT-i9100.
android:splitMotionEvents="false" for holder of buttons
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With