title: Android Declaring Variables before OnCreate?
body: <p>Is it possible to create variables before the <code>onCreate()</code> method in Android? I have tried doing so in the past but to no avail so I'm assuming you cant, but I just want to double check. The reason why is because I am trying to access a variable in my <code>TextWatcher</code> that serves as a counter, but its out of scope and asking for me to make it final, which obviously doesnt work since its serving as a counter and is needed to increment. I have attached my code below: </p>
  
  <pre><code>int counter = 0;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      final EditText answerText = (EditText) findViewById(R.id.answer);
      final TextView text = (TextView) findViewById(R.id.wordtoanswer);
       final ArrayList updatedList = helperMethod();
       text.setText(updatedList.get(0).toString());
       final String wordFinal = updatedList.get(0).toString();
  
       while(true)
       {
      answerText.addTextChangedListener(new TextWatcher() {
          public void onTextChanged(CharSequence s, int start, int before, int count) {
  
              // TODO Auto-generated method stub
          }
  
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
              // TODO Auto-generated method stub
          }
  
          public void afterTextChanged(Editable s) {
              System.out.println(counter);
              String answer = s.toString();
              if(answer.equals(wordFinal))
              {   
                  text.setText(updatedList.get(counter).toString());
                  answerText.setText("");
              }
          }
      });
      counter++;
  }
  }
  </code></pre>
  
  <p>Hopefully you guys understand why I'm trying to declare it before the <code>onCreate()</code>, because only then can the methods inside the <code>TextWatcher</code> actually access it without them being out of scope. Is there anyway I can get around this problem? Please let me know if you need more information/code!</p>