title: on Scroll, value of Spinner resets in Android. How to avoid it
body: <p>I have a spinner which contains dynamic Array data. When I select the value in spinner and scroll down and again scroll up, the value resets, what could be the reason behind this, how can i avoid it. Below is my code :</p>
  
  <pre><code>                spinner.setVisibility(View.VISIBLE);
                  spinner.setOnItemSelectedListener(UserSurveyAdapter.this);
  
                  List&lt;String&gt; list = new ArrayList&lt;String&gt;();
                  int arraysize = oi.getOptList().size();
  
                  Log.d(LOG_TAG, "Size ==" +arraysize );
                  for (int k = 0; k &lt;arraysize; k++) {   
                      if(k == 0){
                          list.add("");
                      }else{
                          list.add(oi.getOptList().get(k));
                      }
  
                  }
  
                  ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(mContext, android.R.layout.simple_spinner_item, list) {
  
                      @Override
                         public View getView(int position, View convertView, ViewGroup parent) {
  
                                 View v = super.getView(position, convertView, parent);
                                 if (position == getCount()) {
                                     ((TextView)v.findViewById(android.R.id.text1)).setText("");
                                     ((TextView)v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
                                 }
  
                                 return v;
                             }       
  
                             @Override
                             public int getCount() {
                                 return super.getCount()-1;            // you don't display last item. It is used as hint.
                             }
  
                     };
  
  
                     adapter.setDropDownViewResource(R.layout.custom_spinner_list);
                     spinner.setAdapter(adapter);
                     spinner.setSelection(adapter.getCount());        //set the hint the default selection so it appears on launch.
                     spinner.setOnItemSelectedListener(this);
                     notifyDataSetChanged();   
  </code></pre>