title: spinner value changes on scrolling list view
body: <p><a href="https://i.stack.imgur.com/RqVW1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RqVW1.jpg" alt="Image"></a></p>
  
  <p>Spinner values changes on scrolling list view, for example if i am selecting NOT OK at first position from my spinner and then scroll down and come back to the top, the spinner values comes  automatically at zero position means at OK. here is my Adapter class and the data in list view is dynamic( varies ).</p>
  
  <p>Code below:</p>
  
  <pre><code>public CustomAdapter(Context context, int resource,
              ArrayList&lt;CustomerDetails&gt; objects) {
          super(context, resource, objects);
          vi = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          Resource = resource;
          list = objects;
      }
  
      public View getView(final int modelPosition, View convertView,
              ViewGroup parent) {
  
          View v = convertView;
          if (v == null) {
              holder = new ViewHolder();
              v = vi.inflate(Resource, null);
  
              java.util.List&lt;String&gt; options = new java.util.ArrayList&lt;String&gt;();
  
              options.add("Ok");
              options.add("Not Ok");
              options.add("Not Recieved");
  
              holder.spinner1 = (Spinner) v.findViewById(R.id.spinner1);
              holder.name = (TextView) v.findViewById(R.id.name);
  
              ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
                      getContext(), android.R.layout.simple_spinner_item,
                      options);
              adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              holder.spinner1.setAdapter(adapter);                 
  
              if (myMap.containsKey(modelPosition)) {
                  holder.spinner1.setSelection(myMap.get(modelPosition));
              }
  
              holder.spinner1.setTag(modelPosition);
              holder.spinner1
                      .setOnItemSelectedListener(new OnItemSelectedListener() {
                          @Override
                          public void onItemSelected(AdapterView&lt;?&gt; parent,
                                  View view, int position, long id) {
                              myMap.put(modelPosition, position);
  
                              if (position == 1) {
  
                                  Status_fos = parent.getItemAtPosition(
                                          position).toString();
  
                                  db.updateMobileStatus(mobile_fos,
                                          Status_fos);
  
                              }
                              if (position == 2) {                         
                                  Status_fos = parent.getItemAtPosition(
                                          position).toString();
  
                                  db.updateMobileStatus(mobile_fos,
                                          Status_fos);
                              }
                              if (position == 3) {     
                                  Status_fos = parent.getItemAtPosition(
                                          position).toString();
  
                                  db.updateMobileStatus(mobile_fos,
                                          Status_fos);
                              }
  
                          }
  
                          @Override
                          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
                              // TODO Auto-generated method stub
  
                          }
                      });
              v.setTag(holder);
          } else {
              holder = (ViewHolder) v.getTag();
          }
  
          holder.name.setText(list.get(modelPosition).getMobile());
          mobile_fos = list.get(modelPosition)
                  .getMobile();
  
          return v;
      }
  
      class ViewHolder {
  
          public Spinner spinner1;
          public TextView name;
          public TextView cid;
  
      }
  }
  </code></pre>