title: How to change listview's button background color when button clicked in android
body: <p>In my application, I keep yes and no button in listview as an item. <strong>setOnClickListener</strong> is defined in <strong>Adapter</strong> class. I have a problem with this. After I scroll the listview, I see the changed button in another row. How can I resolve my issue ?</p>
  
  <pre><code>public class QuizAdapter extends BaseAdapter {
  
      private static final String FONTH_PATH_1 = "fonts/Brandon_reg.otf";
      private static final String FONTH_PATH_2 = "fonts/Brandon_bld.otf";
  
      private ArrayList&lt;Question&gt; questionList = new ArrayList&lt;Question&gt;();
      private LayoutInflater inflater;
  
      private Context context;
  
      public QuizAdapter(Context context) {
          super();
          this.inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          this.context = context;
      }
  
      public void addListItem(final Question item) {
          questionList.add(item);
          notifyDataSetChanged();
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return questionList.size();
      }
  
      @Override
      public Question getItem(int position) {
          // TODO Auto-generated method stub
          return questionList.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          final ViewHolder holder;
  
  
          Question currentQuestion = getItem(position);
  
          Typeface font1 = Typeface.createFromAsset(context.getAssets(),
                  FONTH_PATH_1);
          Typeface font2 = Typeface.createFromAsset(context.getAssets(),
                  FONTH_PATH_2);
  
          if (convertView == null) {
              holder = new ViewHolder();
              convertView = inflater.inflate(R.layout.quiz_list, null);
  
              holder.questionCounterTextView = (TextView) convertView
                      .findViewById(R.id.questionCounterTextView);
              holder.questionCounterTextView.setTypeface(font2);
  
              holder.questionTextView = (TextView) convertView
                      .findViewById(R.id.questionTextView);
              holder.questionTextView.setTypeface(font1);
  
              holder.yesButton = (Button) convertView
                      .findViewById(R.id.yesButton);
              holder.yesButton.setTypeface(font2);
  
              holder.noButton = (Button) convertView.findViewById(R.id.noButton);
              holder.noButton.setTypeface(font2);
  
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
  
  
          }
  
          holder.yesButton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  holder.yesButton.setBackgroundColor(R.color.Gray);
              }
          });
  
          holder.questionCounterTextView.setText(Integer.toString(position + 1));
  
          holder.questionTextView.setText(currentQuestion.getQuestionMessage());
  
          return convertView;
      }
  
      public static class ViewHolder {
          public TextView questionCounterTextView, questionTextView;
          public Button yesButton, noButton;
      }
  
  }
  </code></pre>
  
  <p>xml file</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/White"
      android:orientation="vertical"
      tools:context="...." &gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp" &gt;
  
          &lt;ImageView
              android:id="@+id/flagImageView"
              android:layout_width="80dp"
              android:layout_height="80dp"
              android:layout_alignParentLeft="true"
              android:src="@drawable/flag" /&gt;
  
          &lt;TextView
              android:id="@+id/questionCounterTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/flagImageView"
              android:layout_alignLeft="@+id/flagImageView"
              android:layout_alignRight="@+id/flagImageView"
              android:layout_alignTop="@+id/flagImageView"
              android:layout_marginLeft="10dp"
              android:text="1"
              android:gravity="center|left"
              android:textColor="@color/White" 
              android:textSize="@dimen/question_counter_text_size"/&gt;
  
          &lt;TextView
              android:id="@+id/questionTextView"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:layout_toRightOf="@+id/flagImageView"
              android:text="@string/loremIpsum2"
              android:textColor="@color/Blue"
              android:textSize="@dimen/text_size" /&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/quizLinearLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="30dp"
          android:layout_marginBottom="30dp"
          android:orientation="horizontal"
          android:weightSum="640" &gt;
  
          &lt;Space
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="30" /&gt;
  
          &lt;Button
              android:id="@+id/yesButton"
              style="@style/button_type"
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="275"
              android:background="@color/QuizGreen"
              android:text="@string/yes"
              android:textColor="@color/White"
              android:textSize="@dimen/question_button_text_size" /&gt;
  
          &lt;Space
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="30" /&gt;
  
          &lt;Button
              android:id="@+id/noButton"
              style="@style/button_type"
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="275"
              android:background="@color/QuizOrange"
              android:text="@string/no"
              android:textColor="@color/White"
              android:textSize="@dimen/question_button_text_size" /&gt;
  
          &lt;Space
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="30" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>