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. 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");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.