title: How can I set a variable in a beforeTextChanged method of an edit text listener, and then call that variable outside of that method?
body: <p>I'm trying to get a "previous" button- meaning that before the user types into the text box, a variable is assigned to what the edit text already is. Now I'm trying to get it so that after the text changed listener, a button can be pressed to return to the previous words in the text box. But when I do this, I get the message: symbol cannot be resolved. This is because the onclick listener of the button is a separate method. How can I share this variable?</p>
  
  <pre><code>editText.addTextChangedListener(new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
              final String previousWord = editText.getText().toString();
  
  
          }
  
          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  
          }
  
          @Override
          public void afterTextChanged(Editable editable) {
          }
  
      });
  
  
      btnPrevious.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              view.startAnimation(animScale);
  
  
              editText.setText(previousWord);
  
          }
      });
  </code></pre>