title: ListView repeats Values
body: <p>I am making an app to display data from Mysql database. I used ListView, But I have a problem with the list view if I have the data as the followings : 
  a 
  b
  c
  d 
  to z. 
  The listView displays the number of the records correctly, but the records are repeated and when I go down then I go up to the first row I find that the first Item is not a it changes. where is the problem ?
  I have three classes in the android 
  MainActivity </p>
  
  <p>GetStudentNames</p>
  
  <p>GetStudntNamesAdapter</p>
  
  <pre><code>public class TakingAttendance extends ActionBarActivity {
  
  private Intent intent;
  
  private JSONParser jsonParser = new JSONParser();
  
  
  private ListView mListView;
  private ListViewStudentNameAdapter listViewStudentNameAdapter;
  private ArrayList&lt;ListViewStudentNames&gt; listViewStudentNames;
  
  private String getnames =
          "http://amjad-test.site40.net/getstudentname.php";
  
  private String takingabsence =
          "http://amjad-test.site40.net/takingattendance.php";
  
  private int saving_loop   ;
  
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_taking_attendance);
      mListView = (ListView) findViewById(R.id.Student_names_List);
  
  
  
  
      intent = getIntent();
  
      new GetNames().execute();
  
  
  }
  
  private class GetNames extends AsyncTask&lt;Void, Void, Boolean&gt;
  {
      private ProgressDialog mProgressDialog;
  
  
      private JSONObject jsonObjectResult = null;
  
      private String error;
  
  
      private GetNames()
      {
  
      }
  
  
      @Override
      protected void onPreExecute()
      {
          super.onPreExecute();
          listViewStudentNames = new ArrayList&lt;ListViewStudentNames&gt;();
          mProgressDialog = ProgressDialog.show(TakingAttendance.this,
                  "Processing...", "Get last news", false, false);
  
      }
  
      @Override
      protected Boolean doInBackground(Void... params)
      {
          List&lt;NameValuePair&gt; pairs = new ArrayList&lt;NameValuePair&gt;();
  
          jsonObjectResult = jsonParser.makeHttpRequest(getnames, pairs);
  
          if (jsonObjectResult == null)
          {
              error = "Error in the connection";
              return false;
          }
  
          try
          {
              if (jsonObjectResult.getInt("success") == 1)
              {
                  JSONArray jsonArray = jsonObjectResult.getJSONArray("posts");
                  saving_loop =  jsonArray.length() ;
                  JSONObject news ;
  
                  for (int i = 0; i &lt; jsonArray.length(); i++)
                  {
                      news = jsonArray.getJSONObject(i);
                      ListViewStudentNames listviewstudentname  = new ListViewStudentNames
                              (
                                      news.getString("STUDENT_NAME"),
                                      news.getString("STUDENT_ID")
                              );
  
                      listViewStudentNames.add(listviewstudentname);
                      listviewstudentname.setCheckBox(false);
  
                  }
                  return true;
              }
              else
                  error = jsonObjectResult.getString("message");
  
          }
          catch (Exception ex)
          {
  
          }
  
          return false;
      }
  
      @Override
      protected void onPostExecute(Boolean aBoolean)
      {
          super.onPostExecute(aBoolean);
          mProgressDialog.dismiss();
          if (aBoolean)
          {
              listViewStudentNameAdapter = new ListViewStudentNameAdapter(TakingAttendance.this,
                      listViewStudentNames);
              mListView.setAdapter(listViewStudentNameAdapter);
          }
          else
              Toast.makeText(TakingAttendance.this, error, Toast.LENGTH_LONG).show();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_taking_attendance, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>
  
  <p>the second Class : </p>
  
  <pre><code> public class ListViewStudentNames {
  private  String StudentName ;
  private String StudentID ;
  private boolean selected = false  ;
  
  public ListViewStudentNames(String StudentName, String  StudentID)
  {
      this.StudentName = StudentName ;
      this.StudentID = StudentID;
  
  }
  public ListViewStudentNames( String  StudentID)
  {
      this.StudentID = StudentID;
  
  }
  public boolean getCheckBox() {
      return selected;
  }
  
  public void setCheckBox(boolean selected) {
      this.selected = selected;
  }
  
  public String getStudentID() {
      return StudentID;
  }
  
  public void setStudentID(String studentID) {
      StudentID = studentID;
  }
  
  public String getStudentName() {
      return StudentName;
  }
  
  
  public void setStudentName(String studentName) {
      StudentName = studentName;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The third Class : </p>
  
  <pre><code>  public class ListViewStudentNameAdapter extends ArrayAdapter&lt;ListViewStudentNames&gt; {
  
      private Context mContext;
      private ArrayList&lt;ListViewStudentNames&gt; mData;
  
      private class ViewHolder {
          CheckBox name;
      }
  
      public ListViewStudentNameAdapter (Context mContext, ArrayList&lt;ListViewStudentNames&gt; mData) {
          super(mContext, R.layout.student_names_shape, mData);
          this.mContext = mContext;
          this.mData = new ArrayList&lt;ListViewStudentNames&gt;();
          this.mData.addAll(mData);
      }
  
      @Override
      public int getCount() {
          return mData.size();
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent)
      {
          ViewHolder holder = null;
          Log.v("ConvertView", String.valueOf(position));
  
  
  
          if (convertView == null)
          {
  
              LayoutInflater mInflater = (LayoutInflater)
                      mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
              convertView = mInflater.inflate(R.layout.student_names_shape, null);
              holder = new ViewHolder();
              holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1);
              convertView.setTag(holder);
  
              TextView Student_name = (TextView) convertView.findViewById(R.id.Student_name);
              Student_name.setText(mData.get(position).getStudentName());
              holder.name.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                      CheckBox cb = (CheckBox) v;
                      boolean x;
  
                      ListViewStudentNames country = (ListViewStudentNames) cb.getTag();
  
  
                      if (cb.isChecked()) {
                          country.setCheckBox(true);
                      } else {
                          country.setCheckBox(false);
                      }
  
                  }
              });
  
          }
  
          else {
              holder = (ViewHolder) convertView.getTag();
          }
          ListViewStudentNames country = mData.get(position);
  
          holder.name.setChecked(country.getCheckBox());
          holder.name.setTag(country);
  
          return convertView;
      }
  }
  </code></pre>