title: Set OnClick Listener on button inside list view in android
body: <p>I have a list view in my screen, every list item contains 2 text views and one button.
  On button click i want to take the list item selected index to get some data from a vector.</p>
  
  <p>This is my List Custom Adapter.But i don't know how to do that.</p>
  
  <pre><code>private class CustomAdapter extends ArrayAdapter&lt;ServicesItems&gt; {
  
      public CustomAdapter(Context context, int resource,
              int textViewResourceId, List&lt;ServicesItems&gt; objects) {
          super(context, resource, textViewResourceId, objects);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder = null;
          TextView item = null;
          TextView description = null;
          Button subNowBtn;
  
          ServicesItems ii = getItem(position);
  
          if (null == convertView) {
              convertView = mInflater.inflate(
                      R.layout.list_of_servics_item_2, null);
  
              holder = new ViewHolder(convertView);
              convertView.setTag(holder);
          }
          holder = (ViewHolder) convertView.getTag();
          // cat_name = holder.gettitle();
  
          Resources resources = getResources();
  
          ServicesItems bean1 = (ServicesItems) servicesVector
                  .elementAt(position);
  
          String cat_name_str = bean1.getService_name().toString();
          String descreption = bean1.getDescription().toString();
  
  
          item = holder.getItem();
          item.setText(bean1.getDescription());
  
          description = holder.getDescription();
          description.setText(bean1.getService_name());
  
           subNowBtn=holder.getSubButton();
  
          return convertView;
      }
  
      private class ViewHolder {
          private View mRow;
          private TextView description = null;
          private TextView item = null;
          private Button sub = null;
  
          public ViewHolder(View row) {
              mRow = row;
          }
  
          public TextView getDescription() {
              if (null == description) {
                  description = (TextView) mRow
                          .findViewById(R.id.category_tv);
              }
              return description;
          }
  
          public TextView getItem() {
              if (null == item) {
                  item = (TextView)       
             mRow.findViewById(R.id.descreption_tv);
              }
              return item;
          }
  
          public Button getSubButton(){
              if(null==sub){
                  sub=(Button)findViewById(R.id.subscribe_now_btn);
  
  
              }
              return sub;
          }
  
      }
  
  }
  </code></pre>