title: Listview button id changed on scrolling listview Android
body: <p>In my android application i am using <code>Listview</code> which will have button and textview. Here, I am changing button icon on button click. I have used customAdapter for listview. The functionality of changing button icon is working perfectly. </p>
  
  <p>The problem is that, when i scroll my listview, the icon of other button also gets changed.
  I don't know what is the problem with my code.Please help me to solve this issue.</p>
  
  <p>customAdapter :</p>
  
  <p>public class CustomListViewAdapter_ringtone extends
          ArrayAdapter {</p>
  
  <pre><code>Context context;
  public static MediaPlayer mp = null;
  int btnId;
  String rowTag;
  View previouView = null;
  ListView mListView;
  
  public CustomListViewAdapter_ringtone(Context context, int resourceId,
          List&lt;RowItem_ringtone&gt; items, ListView lst) {
      super(context, resourceId, items);
      this.context = context;
      this.mListView = lst;
  }
  
  private class ViewHolder {
      TextView txtTitle;
      ImageButton btnPlay;
      ImageButton btnSet;
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;
      final RowItem_ringtone rowItem = getItem(position);
  
      LayoutInflater mInflater = (LayoutInflater) context
              .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
      if (convertView == null) {
          convertView = mInflater.inflate(R.layout.ringtone_row, null);
          holder = new ViewHolder();
  
          holder.txtTitle = (TextView) convertView
                  .findViewById(R.id.ringtoneTitle);
          holder.btnPlay = (ImageButton) convertView
                  .findViewById(R.id.btnPlay);
          holder.btnSet = (ImageButton) convertView.findViewById(R.id.btnSet);
          convertView.setTag(holder);
      } else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      holder.txtTitle.setText(rowItem.getRingTitle());
      holder.btnPlay.setTag(rowItem.getRingId());
      holder.btnSet.setTag(rowItem.getRingId());
  
      holder.btnPlay.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              if (CustomListViewAdapter_ringtone.mp != null) {
                  if (CustomListViewAdapter_ringtone.mp.isPlaying()) {
                      CustomListViewAdapter_ringtone.mp.stop();
                      CustomListViewAdapter_ringtone.mp.release();
                      CustomListViewAdapter_ringtone.mp = null;
                  }
              }
              if (previouView != null) {
                  if (previouView != v) {
  
                      previouView.setBackgroundResource(R.drawable.play_icon);
                      v.setBackgroundResource(R.drawable.pause_icon);
                      CustomListViewAdapter_ringtone.mp = MediaPlayer.create(
                              getContext(),
                              Integer.parseInt(v.getTag().toString()));
                      CustomListViewAdapter_ringtone.mp.start();
                      previouView = v;
                  } else {
                      previouView.setBackgroundResource(R.drawable.play_icon);
                      previouView = null;
                  }
              } else {
                  CustomListViewAdapter_ringtone.mp = MediaPlayer.create(
                          getContext(),
                          Integer.parseInt(v.getTag().toString()));
                  CustomListViewAdapter_ringtone.mp.start();
                  v.setBackgroundResource(R.drawable.pause_icon);
                  previouView = v;
              }
          }
      });
  
      holder.btnSet.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String name = rowItem.getRingTitle();
              name = "one_direction_" + name.toLowerCase().replace(" ", "_");
  
              Uri path = Uri.parse("android.resource://"
                      + getContext().getPackageName() + "/raw/" + name);
  
              RingtoneManager.setActualDefaultRingtoneUri(getContext(),
                      RingtoneManager.TYPE_RINGTONE, path);
  
              RingtoneManager.getRingtone(getContext(), path).play();
              Toast.makeText(getContext(), name + " is set as ringtone.",
                      Toast.LENGTH_LONG);
          }
      });
      return convertView;
  }
  </code></pre>
  
  <p>}</p>