title: setOnitemSelectedListener is not triggering with the programmatically created spinner Android
body: <p>My need is to </p>
  
  <ol>
  <li>create a dynamic spinner on a button click</li>
  <li>select the spinner values and set the values into an edit text field.  </li>
  </ol>
  
  <p>For this I have created a dynamic spinner programatically. Put that code inside button click listener. Its working fine upto here.</p>
  
  <p>but the <code>setOnitemSelectedListener</code> of the dynamic spinner is not at all working.. there are no errors in the Logcat... please help me..</p>
  
  <p>------------ These are the methods inside onCreate ------------</p>
  
  <pre><code>Spinner spnOutHospitalList = new Spinner(Referance.this);
  
  // list button on click event
  btnList = (Button) findViewById(R.id.btn_list);
  btnList.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      // TODO Auto-generated method stub
      // function to create spinner dynamically
      createDynamicSpinner();
      }
  });
  
  // Out Hospital List Spinner on item click listener
  spnOutHospitalList.setOnItemSelectedListener(new OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,int position, long arg3) {
      // TODO Auto-generated method stub
      outHospitalName = hospitalNameListArray.get(position);
      outHospital.setText(outHospitalName);
      }
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
      // TODO Auto-generated method stub
      }
  });
  
  
  
  ------------ These are the functions outside onCreate but inside the Activity------------
  
  
  // to create spinner dynamically
  private void createDynamicSpinner() {
      // TODO Auto-generated method stub
      spnOutHospitalList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      loadOutHospitalListSpinner();
      spnOutHospitalList.performClick();
  }
  
  // to load out hospital/ clinic data into spinner
  private void loadOutHospitalListSpinner() {
      // TODO Auto-generated method stub
      try {
          if (getFirstRun()) {
          sampleDB = dbAdapter.getDatabase();
          setRunned();
          } 
          else {
          sampleDB = dbAdapter.getWritableDatabase();
          }
          Cursor c1 = sampleDB.rawQuery("select DISTINCT EPR_OUT_HOSPITAL from EMR_PT_REFERNCE",null);
          System.out.println("count is " + c1.getCount());
  
          if (c1 != null &amp;&amp; c1.getCount() != 0) {
              hospitalNameListArray.clear();
                  if (c1.moveToFirst()) {
                      do {
                          hospitalNameListArray.add(c1.getString(c1.getColumnIndex("EPR_OUT_HOSPITAL")));
                      } while (c1.moveToNext());  
                  }
              }
              c1.close();
  
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, hospitalNameListArray);
  
              // dropdownlist
              dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
              spnOutHospitalList.setAdapter(dataAdapter);
  
          } 
          catch (Exception e) {
              // TODO: handle exception
              System.out.println("CAT LIST ERROR IS: " + e.getMessage());
          }
  
      }
  </code></pre>