title: how to access global variable in fragment android
body: <p>I am trying to access the method local variable and assign to a global variable and try to access it to other methods code is working fine for local but not assigned to the global variable here is my code</p>
  
  <pre><code>global variable String spinner;
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  View view= inflater.inflate(R.layout.fragment_players, container, false);
  //I want to get value here
  }
  
  //private void Spinner(List&lt;String&gt; list)
  {
  spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  @Override
  public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
      if (i&gt;0)
      {
       String text= spinner.getSelectedItem().toString();
       spinnerText=text;
      }
  }
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
      }
  });
  
  }
  </code></pre>