Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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
在Android Studio中输入文本时有没有显示文本的方法?_Android_Android Studio_Textview - Fatal编程技术网

在Android Studio中输入文本时有没有显示文本的方法?

在Android Studio中输入文本时有没有显示文本的方法?,android,android-studio,textview,Android,Android Studio,Textview,在Android Studio的文本字段中键入输入时,有没有一种方法可以自动在屏幕上显示文本 例如,如果我输入一个数字,它会自动乘以20,结果显示在文本字段下方的屏幕上。我无法正确理解这个问题,因此下面是两种不同情况的解决方案 要显示的文本位于同一活动或框架中。 使用这样的TextWatcher类 输出在不同的屏幕片段/抽屉中 您可以使用TextWatcher和LiveData的组合来实现。 在editText上放置TextWatcher,并将数据存储在Livedata中。 然后观察此liveD

在Android Studio的文本字段中键入输入时,有没有一种方法可以自动在屏幕上显示文本


例如,如果我输入一个数字,它会自动乘以20,结果显示在文本字段下方的屏幕上。

我无法正确理解这个问题,因此下面是两种不同情况的解决方案

要显示的文本位于同一活动或框架中。 使用这样的TextWatcher类 输出在不同的屏幕片段/抽屉中 您可以使用TextWatcher和LiveData的组合来实现。 在editText上放置TextWatcher,并将数据存储在Livedata中。
然后观察此liveData并相应地更改Textview。

一个简单的方法是使用Textview事件侦听器来处理您的操作! 以下是你如何做到这一点

    field1 = (EditText)findViewById(R.id.field2);
    
    field1.addTextChangedListener(new TextWatcher() 
    {        
       public void afterTextChanged(Editable s)    
     {     //Called after the changes have been applied to the text.
           //You can change the text in the TextView from this method.

     }  
       public void beforeTextChanged(CharSequence s, int start,
         int count, int after) {
         //Called before the changes have been applied to the text.

       }
    
       public void onTextChanged(CharSequence s, int start,int before, int count) {
          TextView.setText("Here is the changing text"+s);
     //Similar to the beforeTextChanged method but called after the text changes.
    
    
       }
      });
/* 您可以防止这样的无限循环

@Override
        public void afterTextChanged(Editable s) {
            if (_ignore)
                return;

            _ignore = true; // prevent infinite loop
            // Change your text here.
            // myTextView.setText(myNewText);
            _ignore = false; // release, so the TextWatcher start to listen again.
        }
*/

我真的不明白你为什么需要实时数据,因为你可以在文本观察程序中更改它。。
@Override
        public void afterTextChanged(Editable s) {
            if (_ignore)
                return;

            _ignore = true; // prevent infinite loop
            // Change your text here.
            // myTextView.setText(myNewText);
            _ignore = false; // release, so the TextWatcher start to listen again.
        }
*/