title: Spinner OnItemSelectedListener is not working and spinner not displaying selected item on spinner
body: <p>Here populating spinner with dynamic values coming from json url. i'm getting values in spinner but their are not visible when selected as showing below.</p>
  
  <pre><code>    @Override
  
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.spintoolbaractivity);
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      spinner_nav = (Spinner) findViewById(R.id.spinner_nav);
      if (toolbar != null) {
          setSupportActionBar(toolbar);
          getSupportActionBar().setDisplayShowTitleEnabled(false);
  
      }
      new GetTeacher().execute();
  
  }
  private class GetTeacher extends AsyncTask&lt;Void, Void, Void&gt;
  {
  
      @Override
      protected void onPreExecute()
      {
          super.onPreExecute();
          // Showing progress dialog
          pDialog = new ProgressDialog(SpinToolbarActivity.this);
          pDialog.setMessage("Please wait...");
          pDialog.setCancelable(false);
          pDialog.show();
  
      }
  
      @Override
      protected Void doInBackground(Void... arg0)
      {
          Lclasslist = new ArrayList&lt;String&gt;();
          JsonObjectRequest req = new JsonObjectRequest(
                  url_all_teacher, null, new    Response.Listener&lt;JSONObject&gt;(){
              @Override
              public void onResponse(JSONObject jsonObj) {
                  Log.d("reponse", jsonObj.toString());
  
                  try {
                      if (jsonObj != null)
                      {
  
  
  
                          class_details = jsonObj.getJSONArray(TAG_class_details);
                              String loginToken=class_details.toString();
                              String fstr=loginToken.substring(1, loginToken.length() - 1);
                              JSONObject jsonObj2 = new JSONObject(fstr);
                              JSONObject d = class_details.getJSONObject(0);
  
                              int success2 =d.getInt(TAG_SUCCESS);
  
                              if (success2 == 1)
                              {
                                  class_details2= jsonObj2.getJSONArray(TAG_class_details2);
                                  // looping through All Products
                                  for (int i = 0; i &lt; class_details2.length(); i++)
                                  {
                                      JSONObject c = class_details2.getJSONObject(i);
  
  // adding ArrayList and this list is added to spinner   
                              Lclasslist.add(c.getString("class_id"));
  
                                  }
                              }
                              else
                              {
                                  //setnoclssp();
  
                              }
  
                      } else {
                          //Log.e("ServiceHandler", "Couldn't get any data from the url");
                      }
  
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                      Toast.makeText(getApplicationContext(),
                              "Error: " + e.getMessage(),
                              Toast.LENGTH_LONG).show();
                  }
  
                  hidepDialog();
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  VolleyLog.d(TAG_class_details, "Error: " + error.getMessage());
                  Toast.makeText(getApplicationContext(),
                          error.getMessage(), Toast.LENGTH_SHORT).show();
                  hidepDialog();
              }
          });
  
          // Adding request to request queue
          AppController.getInstance().addToRequestQueue(req);
  
          return null;
      }
      @Override
      protected void onPostExecute (Void result)
      {
          addItemsToSpinner();
      }
  
  
  }
  </code></pre>
  
  <p>// add items into spinner dynamically</p>
  
  <pre><code>public void addItemsToSpinner()
  </code></pre>
  
  <p>{</p>
  
  <p>// Custom ArrayAdapter with spinner item layout to set popup background</p>
  
  <pre><code>          CustomSpinnerAdapter spinAdapter = new CustomSpinnerAdapter(
           getApplicationContext(), Lclasslist);
           spinner_nav.setAdapter(spinAdapter);
           spinner_nav.setOnItemSelectedListener(new       OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; adapter, View v,
                  int position, long id) {
              // On selecting a spinner item
              String item = adapter.getItemAtPosition(position).toString();
  
              // Showing selected spinner item
              Toast.makeText(getApplicationContext(), "Selected  : " + item,
                      Toast.LENGTH_LONG).show();
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
              // TODO Auto-generated method stub
  
          }
      });
  
  }
  private void showpDialog() {
      if (!pDialog.isShowing())
          pDialog.show();
  }
  
  private void hidepDialog() {
      if (pDialog.isShowing())
          pDialog.dismiss();
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/aBuDX.png" rel="nofollow">Image when i select spinner</a></p>
  
  <p><a href="http://i.stack.imgur.com/sFBoj.png" rel="nofollow">Image when i select spinner item</a></p>