![](/img/trans.png)
[英]How to stop the android application sending the pending location to webserver when i clicked on the logout button?
[英]How can i stop sending messages which are sending in loop on click of an button in android
我想知道如何停止循环中的消息发送。
当我按停止键时,仍会发送消息。
我提供了stop()
方法。
for (i = 0; i < copy; i++) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(stop!=1)
sms.sendTextMessage(number,null,message,sentPIn,pdelint);
}
}, 25000);
stop method
int stop=0;
public void st(View view){
Button b=(Button)findViewById(R.id.button2);
b.setText("Stopped");
stop=1;
}
修改St函数对此
public void st() {
Button b = (Button) findViewById(R.id.button);
@Override
b.setOnClickListener(new View.OnClickListener() {
b.setText("Stopped!");
stop=1;
});
}
问题是您没有使用侦听器来检测按钮的按下情况。 建议不要使用文本视图来更改按钮文本!
他很可能已经在xml中设置了onClick
属性,尽管只有他才能澄清这一点。
我说这是因为我在方法st(View v)
中将View视为参数。
尽管如果未在xml中设置onClick属性,则@Audi的解决方案会很好。 相反,如果已在xml中设置了属性,则应检查view.getId() == R.id.button
然后将按钮view.getId() == R.id.button
应用到视图并将其文本设置为“ Stopped”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.