title: how to access from onCreateCiew to setOnItemSelectedListener method variable
body: <p>I am not an expert in android studio with java and I would like to know how to obtain the value declared within the setOnItemSelectedListener method (variable option_name). I have declared a spinner which shows a series of options, what I want is to extract the option to use it in the onCreateView for later insert it in a database together with other texts that are obtained from editText. Greetings
  my code:</p>
  <pre><code>public class genera_debate extends Fragment {
      EditText date,time_hour;
      TextView test;
      Spinner list_of_interest;
      Button PostDiscussion;
      public String name_perfil,alias_perfil,option_interest,option_name;
      
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view=inflater.inflate(R.layout.fragment_genera_debate,container,false);
          test =view.findViewById(R.id.test);
          PostDiscussion= view.findViewById(R.id.button4);
          list_of_interest =view.findViewById(R.id.subject_of_interest);
          String [] subject = {&quot;Tema de interés&quot;,&quot;Política&quot;,&quot;Deporte&quot;,&quot;Animales&quot;,&quot;Videojuegos&quot;,&quot;Economía&quot;,&quot;Medicina&quot;,&quot;Cultura&quot;,&quot;Ciencia&quot;,&quot;Tecnología&quot;,&quot;Música&quot;,&quot;Otros&quot;};
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getContext(), android.R.layout.simple_spinner_item, subject);
          list_of_interest.setAdapter(adapter);
          list_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  option_name = (String ) parent.getItemAtPosition(position);
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
              }
          });
      
          return view;
      }
  </code></pre>