title: How to get String from setOnItemSelectedListener method?
body: <p>I'm new to Android and I'm trying to get a String from spinner. I've made some research but I couldn't find anything useful. Without trying to get String the code is working properly. This is the code which is working:</p>
  
  <pre><code>assert staticSpinner2 != null;
      staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
  
          }
  
          public String getSpin(String spinnerLanguage2) {
              return spinnerLanguage2;
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  </code></pre>
  
  <p>I tried to use a getter method as follows where I didn't get any errors:</p>
  
  <pre><code>assert staticSpinner2 != null;
      staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
  
          }
  
          public String getSpinnerString(String spinnerLanguage2) {
              return spinnerLanguage2;
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  </code></pre>
  
  <p>I'm trying to set this String to a text view using:</p>
  
  <pre><code>assert staticSpinner2 != null;
      staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
  
          }
  
          public String getSpinnerString(String spinnerLanguage2) {
              return spinnerLanguage2;
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  
      MainActivityClassName AnObject = new MainActivityClassName();
      text.setText(AnObject.getSpinnerString());
  </code></pre>
  
  <p>Where I get an error saying "cannot resolve method getSpin()". I do realise I'm not passing any parameters to the method but I don't know how I can do it here. I appreciate any help or any other advice to solve the problem in a different way. Thanks in advance.</p>
  
  <p>This is the full code if that helps:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  TextView text;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_json);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      text = (TextView) findViewById(R.id.textView);
  
      // spinner 1
      final Spinner staticSpinner1 = (Spinner) findViewById(R.id.spinner1);
  
      // Create an ArrayAdapter using the string array and a default spinner
      ArrayAdapter&lt;CharSequence&gt; staticAdapter1 = ArrayAdapter
              .createFromResource(this, R.array.lang,
                      android.R.layout.simple_spinner_item);
  
      // Specify the layout to use when the list of choices appears
      staticAdapter1
              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      // Apply the adapter to the spinner
      staticSpinner1.setAdapter(staticAdapter1);
  
  
  
      // spinner 2
      final Spinner staticSpinner2 = (Spinner) findViewById(R.id.spinner2);
  
      staticSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                                     int arg2, long arg3) {
              String spinnerLanguage = staticSpinner1.getSelectedItem().toString();
  
  
              switch (spinnerLanguage) {
                  case "Afrikaans":
                      // Create an ArrayAdapter using the string array and a default spinner
                      ArrayAdapter&lt;CharSequence&gt; staticAdapterAF = ArrayAdapter
                              .createFromResource(getBaseContext(), R.array.af,
                                      android.R.layout.simple_spinner_item);
  
                      // Specify the layout to use when the list of choices appears
                      staticAdapterAF
                              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
                      // Apply the adapter to the spinner
                      staticSpinner2.setAdapter(staticAdapterAF);
                      break;
                  case "French":
                      // Create an ArrayAdapter using the string array and a default spinner
                      ArrayAdapter&lt;CharSequence&gt; staticAdapterFR = ArrayAdapter
                              .createFromResource(getBaseContext(), R.array.fr,
                                      android.R.layout.simple_spinner_item);
  
                      // Specify the layout to use when the list of choices appears
                      staticAdapterFR
                              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
                      // Apply the adapter to the spinner
                      staticSpinner2.setAdapter(staticAdapterFR);
                      break;
                  case "English":
                      // Create an ArrayAdapter using the string array and a default spinner
                      ArrayAdapter&lt;CharSequence&gt; staticAdapterEN = ArrayAdapter
                              .createFromResource(getBaseContext(), R.array.en,
                                      android.R.layout.simple_spinner_item);
  
                      // Specify the layout to use when the list of choices appears
                      staticAdapterEN
                              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
                      // Apply the adapter to the spinner
                      staticSpinner2.setAdapter(staticAdapterEN);
                      break;
                  case "Turkish":
                      // Create an ArrayAdapter using the string array and a default spinner
                      ArrayAdapter&lt;CharSequence&gt; staticAdapterTR = ArrayAdapter
                              .createFromResource(getBaseContext(), R.array.tr,
                                      android.R.layout.simple_spinner_item);
  
                      // Specify the layout to use when the list of choices appears
                      staticAdapterTR
                              .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
                      // Apply the adapter to the spinner
                      staticSpinner2.setAdapter(staticAdapterTR);
                      break;
              }
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
  
          }
  
      });
  
  
      assert staticSpinner2 != null;
      staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
  
  
          }
  
          public String getSpin(String spinnerLanguage2) {
              return spinnerLanguage2;
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  
      MainActivity AnObject = new MainActivity();
      text.setText(AnObject.getSpinnerString());
  
  }
  </code></pre>
  
  <p>}</p>