title: android Button inside custom listview
body: <p>I have developed an Android application using custom <code>ListView</code>. My custom <code>ListView</code> consists of <code>Textview</code>, <code>ImageView</code> and 2 <code>ImageButton</code>s. I want to change my <code>ImageButton</code>'s resource when I click it. (example: from play to stop). More clearly, I attach my design below.</p>
  
  <p><img src="https://i.stack.imgur.com/01V4e.png" alt="enter image description here"></p>
  
  <p>How can I control my <code>ImageButton</code> from <code>Activity</code>?</p>
  
  <pre><code>public class MyCustomBaseAdapterSurat extends BaseAdapter {
      private static ArrayList&lt;SearchResults&gt; searchArrayList;
  
      private LayoutInflater mInflater;
      ViewHolder holder;
      private StreamingMediaPlayer audioStreamer;
  
      public MyCustomBaseAdapterSurat(Context context,
              ArrayList&lt;SearchResults&gt; results) {
          searchArrayList = results;
          mInflater = LayoutInflater.from(context);
      }
  
      @Override
      public int getCount() {
          return searchArrayList.size();
      }
  
      @Override
      public Object getItem(int position) {
          return searchArrayList.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          if (convertView == null) {
              convertView = mInflater.inflate(R.layout.customlistsurat, null);
              holder = new ViewHolder();
              holder.txtName = (TextView) convertView.findViewById(R.id.name);
              holder.iv = (ImageView) convertView.findViewById(R.id.imageView1);
              holder.play = (ImageButton) convertView
                      .findViewById(R.id.imageButton1);
              holder.rep = (ImageButton) convertView
                      .findViewById(R.id.imageButton2);
               holder.play.setOnClickListener(klikplay);
          //   holder.rep.setOnClickListener(klikrep);
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
          holder.rep.setId(searchArrayList.get(position).getIdRep());
          holder.play.setId(searchArrayList.get(position).getIdPlay());
          holder.txtName.setText(searchArrayList.get(position).getName());
          holder.iv.setBackgroundResource(searchArrayList.get(position)
                  .getDrawable());
          return convertView;
      }
  
      static class ViewHolder {
          TextView txtName;
          ImageView iv;
          ImageButton play;
          ImageButton rep;
      }
  
      private OnClickListener klikplay = new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              holder.play.setBackgroundResource(searchArrayList.get(v.getId())
                      .getDrawable());
              //startStreamingAudio();
          }
      };
  
  }
  </code></pre>