title: Cannot refer to a non-final variable inside an inner class defined in a different method- Please help me i am new at this
body: <p>Please, help me. I am trying to build a simple application in which you select a hobby from a spinner you click in the button "aceptar" and its return the string from that spinner to the main activity. I am getting the error "cannot refer to a non-final variable inside an inner class defined in a different method" in the variable "myspinner".</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.Spinner;
  import android.widget.TextView;
  
      public class ActivitySaludo extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_saludo);
          String myspinner;
  
          Intent intent = getIntent();
          String saludo = intent.getStringExtra(MainActivity.EXTRA_SALUDO);
  
          TextView txtCambiado = (TextView) findViewById(R.id.TxtSaludo);
          txtCambiado.setText(getString(R.string.hola_saludo) + " " + saludo);
  
          final Spinner spinner = (Spinner)findViewById(R.id.SpinnerSaludo);
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this, R.array.hobby, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
          spinner.setAdapter(adapter);
  
          spinner.setOnItemSelectedListener(new OnItemSelectedListener () {
  
  
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                      int pos, long id) {
                  parent.getItemAtPosition(pos);
                  myspinner = spinner.getItemAtPosition(pos).toString();
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                  //another call
  
              }
  
          });
  
          final Button BtnAceptar=(Button) findViewById(R.id.buttonAceptar);
          BtnAceptar.setOnClickListener(new OnClickListener (){
  
              @Override
              public void onClick(View v) {
                  Intent iboton = new Intent();   
  
  
              }
  
          });
  
      }
  
  }
  </code></pre>