title: Android: How to declare global objects (textviews, buttons) and modify them with functions
body: <p>I am able to create a global object like a button or textview but I am not able to use them in my functions. </p>
  
  <p>I'd like to create a global textview or edittext view where I will be able to read and modify its contents with my functions.</p>
  
  <p>This is an example, I created a textview under onCreate called "titles"</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
   @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          TextView titles = (TextView)findViewById(R.id.textView);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
      }
  </code></pre>
  
  <p>Later in the same activity, I have a function that tries to modify its text, instead I get an error saying cannot resolve.</p>
  
  <pre><code>public void win(){
  
  titles.setText("Second text to display!");
  
  }
  </code></pre>