title: List view messing up on scrolling
body: <p>I know there are numerous answers to this question on stackoverflow, and I did go through as many as i found. But, I did not land to any solution for my problem.</p>
  
  <p>My problem:</p>
  
  <p>I am making an attendance system for a startup. second activity in app, takes employee data from sql server and display them in the list. my list item has a text view and a button in it. Button displays the status of employee. Now, when I click the button, there is a duplicacy in state change of the button. suppose i do it for 1 item then it occurs for another item in the list when being scrolled.</p>
  
  <p>what  I tried:</p>
  
  <p>studied the concept of custom adapter and overriding the get view in adapter class.
  studied recycling concept in list view and holder concept. </p>
  
  <p>still not able to solve. please suggest something.</p>
  
  <p>Here is the code from the adapter class: </p>
  
  <pre><code>package mywork.attendance_system;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.graphics.Color;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Created by Harshul on 8/24/2015.
   */
  public class custom_adapter extends ArrayAdapter&lt;String&gt; {
  
      private LayoutInflater inflater;
     // private int[] colors;
      ArrayList&lt;String&gt; emp;
      //ArrayList&lt;Boolean&gt; status;
  
      public custom_adapter(Activity activity , ArrayList&lt;String&gt; items)
          {
              super(activity, R.layout.rowlayout, items);
              inflater = activity.getWindow().getLayoutInflater();
              emp=items;
        //      this.status=status;
              Log.d("1111",emp.get(1));
             // this.colors[0]=Color.parseColor("#FFFFF");
             // this.colors[1]=Color.parseColor("#D2E4FC");
          }
  
      static class ViewHolder{
          public TextView tview;
          public Button b1;
  
      }
      @Override
      public View getView(int position, View convertView, final ViewGroup parent){
         ViewHolder viewHolder = null;
          if (convertView==null)
          {
          convertView = inflater.inflate(R.layout.rowlayout, null);
          viewHolder = new ViewHolder();
          viewHolder.tview=(TextView)convertView.findViewById(R.id.t1);
          viewHolder.b1=(Button)convertView.findViewById(R.id.A);
              convertView.setTag(viewHolder);
          }
  else
          {
              viewHolder=(ViewHolder)convertView.getTag();
          }
          final ViewHolder finalViewHolder = viewHolder;
          viewHolder.b1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  LinearLayout parentRow = (LinearLayout) v.getParent();
                  ListView listView = (ListView) parentRow.getParent();
                  final int position1 = listView.getPositionForView(parentRow);
  
                  if((finalViewHolder.b1.getText()).equals("A")) {
                      finalViewHolder.b1.setText("P");
                      //            status.set(position1,true);
                      //          Log.d("statussss",String.valueOf(status.get(position1)));
                  }
                  else {
                      finalViewHolder.b1.setText("A");
                      //        status.set(position1,false);
                      //      Log.d("statussss",String.valueOf(status.get(position1)));
                  }
              }});
  
  
          finalViewHolder.tview.setText(String.valueOf(emp.get(position)));
  
          if (position%2==1)
          {
              finalViewHolder.tview.setBackgroundColor(Color.parseColor("#F0F0F0"));
          }
          else
          {
              finalViewHolder.tview.setBackgroundColor(Color.parseColor("#D2E4FC"));
          }
  
  
  
              return convertView;
  
          }
  
      }
  </code></pre>
  
  <p>My xml file for layout of the list item</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:weightSum="1"&gt;
  
      &lt;TextView
          android:id="@+id/t1"
          android:layout_width="237dp"
          android:layout_height="wrap_content"
          android:textSize="20sp"
          android:padding="20dp"
          android:textColor="#222222"
          android:textStyle="bold"
          /&gt;
      &lt;Button
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:id="@+id/A"
          android:text="A"
          android:textSize="20dp"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>if you need anything else just say, i will upload it.</p>
  
  <p><a href="https://i.stack.imgur.com/6f4AL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6f4AL.png" alt="how my screen looks like"></a>
  <a href="https://i.stack.imgur.com/gCgbH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gCgbH.png" alt="duplicacy"></a></p>