简体   繁体   English

Android中的开始/停止按钮

[英]Start/stop button in Android

Such a simple thing (hence username) but I just want a start/stop button, it's for a timer but for simplicity we'll go by "starty" and "stoppy" instead of a timer running and a timer not running. 这样的事情很简单(因此使用用户名),但是我只想要一个开始/停止按钮,它用于计时器,但是为了简单起见,我们将按“ starty”和“ stoppy”进行操作,而不是运行计时器和不运行计时器。 I don't want to ask for you to do my code, but if anyone could tell me what I'm missing I'd really love that. 我不想让您编写代码,但是如果有人可以告诉我我所缺少的内容,我将非常喜欢。

Thanks! 谢谢! :) :)

public void onClick(View v) {
            if (helloWorld.getText().length() == 0
                    || helloWorld.equals("stoppy")) {
                helloWorld.setText("starty");
            } else {
                helloWorld.setText("stoppy");
            }
        }

我认为这可能是一个问题。.添加像helloWorld.getText()。trim.equals(“ stoppy”)来匹配两个字符串

use like that 这样使用

public void onClick(View v) {
            if (helloWorld.getText().trim().length() == 0
                    || helloWorld.getText().trim().equals("stoppy")) {
                helloWorld.setText("starty");
            } else {
                helloWorld.setText("stoppy");
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM