android - If-else to control button event -
here connected laptop , android through bluetooth.
my question , how can set info when don't force button.
my android application sends +,- when press +button , - button.
if press + button, programme in laptop increment value, , - button gives opposite result.
but need 1 1 alter in value.
that means, 1 click increment value in 1 time, not continuously increasing value.
the code below sends info pushed in lastly when don't force button.
bundle remote.bluetooth; import android.app.activity; import android.content.context; import android.content.intent; import android.graphics.canvas; import android.graphics.color; import android.graphics.paint; import android.graphics.paint.style; import android.os.bundle; import android.view.motionevent; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.textview; public class mouseactivity extends activity implements onclicklistener{ int score = 0; textview value; button plus, minus; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.mouseactivity); plus = (button) findviewbyid(r.id.rclick); minus = (button) findviewbyid(r.id.lclick); value = (textview) findviewbyid(r.id.number); plus.setonclicklistener((onclicklistener) this); minus.setonclicklistener((onclicklistener) this); //왼 클릭 버튼 생성 및 이벤트 연결 } public void onclick(view v) { if(v.getid()==r.id.rclick) { string msg = "+"; main.getinstance().sendmessage(msg); score++; value.settext(string.valueof(score)); } else if (v.getid()==r.id.lclick) { string msg = "-"; main.getinstance().sendmessage(msg); score--; value.settext(string.valueof(score)); } else { string msg = "0"; main.getinstance().sendmessage(msg); }} }
and send message method
public void sendmessage(string mmsg) { // check we're connected before trying if (mconnection.getstate() != bluetoothconnection.state_connected) { toast.maketext(this, r.string.not_connected, toast.length_short).show(); return; } // check there's send if (mmsg.length() > 0) { // message bytes , tell bluetoothchatservice write byte[] send = mmsg.getbytes(); mconnection.write(send); } }
you incrementing , decrementing score
variable twice.
here:
case r.id.rclick: score++; showtext = true; break;
and here:
if(v.getid()==r.id.rclick){ string msg = "+"; main.getinstance().sendmessage(msg); score++; value.settext(string.valueof(score)); }
android if-statement
No comments:
Post a Comment