I am developing an App. It has multiple button
, each button
will send the TCP data
to the Server
.
For example: There has three Button for Button-A
, Button-B
and Button-C
. The Button-A
will send the "A" to the Server , etc.
private static String data;
btn_A.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
data = "A";
send(data);
}
});
btn_B.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
data = "B";
send(data);
}
});
btn_C.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
data = "C";
send(data);
}
});
If I click the Button from Button-A
to Button-C
quickly. The Server will receive data for three times. It is inefficient...
How to implement click multiple button but only working for last time click ?
I want the App only send the data for the last button which I have click if I click the Button from Button-A
to Button-C
quickly.
I have try to use the thread
for sending data to Server every 3 second. It will send the last value of data
every 3 second.
Does there has other better way to do this ?