Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用户输入运行时android_Java_Android - Fatal编程技术网

Java 用户输入运行时android

Java 用户输入运行时android,java,android,Java,Android,我正在尝试在Android中构建一个简单的转换代码(将脚转换为mtr)。我能够做到这一点,但只有当用户点击一些按钮。现在我想修改它,这样当用户输入时它就会开始转换(类似于GoogleConverter)。在Android中有什么方法可以做到这一点吗? 提前感谢。将侦听器添加到编辑文本中: yourEditText.addTextChangedListener(addTextWatcher); 添加TextWatcher界面: private TextWatcher addTextWatcher

我正在尝试在Android中构建一个简单的转换代码(将脚转换为mtr)。我能够做到这一点,但只有当用户点击一些按钮。现在我想修改它,这样当用户输入时它就会开始转换(类似于GoogleConverter)。在Android中有什么方法可以做到这一点吗?
提前感谢。

将侦听器添加到编辑文本中:

yourEditText.addTextChangedListener(addTextWatcher);
添加TextWatcher界面:

private TextWatcher addTextWatcher = new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence sequence, int start, int before, int count) {
        // here is where you could grab the contents of the edittext 
        // input each time a character is entered, and pass the value 
        // off to your unit conversion code. Careful to check for 
        // numerals/decimals only, or to set the proper inputType in 
        // your xml.
    }
    @Override
    public void beforeTextChanged(CharSequence sequence, int start, int count, int after) { 

    }
    @Override
    public void afterTextChanged(Editable sequence) { 

    }
};
TextWatcher: