android 如何获得字符的值,同时在编辑文本框中键入另一个文本框?

qc6wkl3g  于 2023-01-07  发布在  Android
关注(0)|答案(3)|浏览(181)

在Android Studio的编辑文本框中键入内容时,如何获取文本框中字符的值?例如,如果用户在编辑文本框中写入A,则在第二个文本框中,A的值应视为20。同样,其他字符应被赋予特定值。

textView.setText(editText.getText().toString())
nbysray5

nbysray51#

查看文本观察器-https://developer.android.com/reference/android/text/TextWatcher

TextWatcher textWatcher = new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
...
    }
...
};

textView.addTextChangedListener(textWatcher);
7uzetpgm

7uzetpgm2#

使用文本观察器和转换像这样

val codeValue = 'A'.code // 'A' dynamic
textView.setText(codeValue.toString())
4uqofj5v

4uqofj5v3#

使用文本监视器

youredittext.addTextChangedListener(new TextWatcher()
    {
        @Override
        public void afterTextChanged(Editable mEdit) 
        {
            text = mEdit.toString();
           textView.setText(text)
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after){}

        public void onTextChanged(CharSequence s, int start, int before, int count){}
    });

相关问题