title: Spinner setSelection data is going to vanish when scrolling ListView
body: <p>Hi I am new for android and in my ListView,I have added Spinner.</p>
  
  <p>I am facing problem,when I have selected any item from spinner and,I scroll my ListView.
  Spinner setSelection data is being vanished. </p>
  
  <p>Please help me how can I resolve this problem ?</p>
  
  <h2>MainActivity:-</h2>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private ArrayList&lt;Friend&gt; friendArrayList;
  
      String[] countriessArray =  { "USA", "USA", "USA", "USA",
              "China", "Japan", "France", "USA","USA", "USA", "USA", "USA",
              "China", "Japan", "France", "USA"};
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_layout);
  
          friendArrayList = new ArrayList&lt;Friend&gt;();
          for (int i = 0; i &lt; countriessArray.length; i++) {
  
              Friend item = new Friend(countriessArray[i]);
              friendArrayList.add(item);
          }
  
          ListView listView = (ListView) findViewById(R.id.list);
  
          ListViewAdapter adapter = new ListViewAdapter(this, R.layout.item_listview, friendArrayList);
  
          listView.setAdapter(adapter);
      }
  }
  </code></pre>
  
  <h2>ListViewAdapter:-</h2>
  
  <pre><code>public class ListViewAdapter extends ArrayAdapter&lt;Friend&gt; implements AdapterView.OnItemSelectedListener {
  
      private List&lt;Friend&gt; myFriends;
      private Activity activity;
      private int selectedPosition = -1;
  
      public ListViewAdapter(Activity context, int resource, List&lt;Friend&gt; objects){
  
          super(context, resource, objects);
          this.activity = context;
          this.myFriends = objects;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          ViewHolder holder;
          LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
  
          // If holder not exist then locate all view from UI file.
          if (convertView == null) {
              // inflate UI from XML file
              convertView = inflater.inflate(R.layout.item_listview, parent, false);
              // get all UI view
              holder = new ViewHolder(convertView);
              // set tag for holder
              convertView.setTag(holder);
          } else {
              // if holder created, get tag from view
              holder = (ViewHolder) convertView.getTag();
          }
  
          holder.checkBox.setTag(position); // This line is important.
          holder.friendName.setText(getItem(position).getName());
  
          if (position == selectedPosition) {
              holder.checkBox.setChecked(true);
          } else holder.checkBox.setChecked(false);
          holder.checkBox.setOnClickListener(onStateChangedListener(holder.checkBox, position));
  
          // Spinner Drop down elements
  
          List&lt;String&gt; categories = new ArrayList&lt;String&gt;();
          categories.add("Automobile");
          categories.add("Business Services");
          categories.add("Computers");
          categories.add("Education");
          categories.add("Personal");
          categories.add("Travel");
  
          // Creating adapter for spinner
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(activity, android.R.layout.simple_spinner_item, categories);
  
          // Drop down layout style - list view with radio button
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
          // attaching data adapter to spinner
          holder.spinner.setAdapter(dataAdapter);
  
          holder.spinner.setOnItemSelectedListener(this);
  
          return convertView;
      }
  
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          // On selecting a spinner item
      }
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          // TODO Auto-generated method stub
      }
  
      private View.OnClickListener onStateChangedListener(final CheckBox checkBox, final int position) {
          return new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  if (checkBox.isChecked()) {
                      selectedPosition = position;
                  } else {
                      selectedPosition = -1;
                  }
                  notifyDataSetChanged();
              }
          };
      }
  
      private static class ViewHolder {
  
          private TextView friendName;
          private CheckBox checkBox;
          private Spinner spinner;
  
          public ViewHolder(View v) {
  
              checkBox = (CheckBox) v.findViewById(R.id.check);
              friendName = (TextView) v.findViewById(R.id.name);
              spinner = (Spinner) v.findViewById(R.id.spinnerList);
          }
      }
  }
  </code></pre>
  
  <h2>Friend:-</h2>
  
  <pre><code>public class Friend {
  
      private String name;
  
      public Friend(String name) {
          this.name = name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
  }
  </code></pre>