如何检查用户定义的(EditText)时间量是否正确?

I'm attempting to implement a function in Android (Java) that has a user enter a int in an EditText and use that Specific int's value in seconds to determine if that a statement is true for that many seconds and return a result, otherwise, restart the check to see if the condition has been true for user-defined amount of seconds.

我一直在尝试这样的事情

//Under MainActivity
public double userDefined = Double.parseDouble(editText.getText().toString()); //Returns Null Pointer Error?

//Function in MainActivity
private Runnable Condition = new Runnable() {
        private boolean killed = false;
        boolean flag = true;

        public void run() {
            while (!killed) {
                try {
                    if (valueA < valueB) {
                        while (flag) {
                            TimeUnit.SECONDS.sleep((long) userDefined);
                            if ((valueB < valueA)) {
                                /* Do stuff */
                                flag = false;
                            }
                        }

                    }
                   catch(InterruptedException ex){
                        killed = true;
                    }
                }
            }
        }
    }
// Not sure if done here need to return stuff done...
评论