title: Implement onClick listener in Listview adapter class
body: <p>I have a Activity which shows json that has objects set as <strong>name</strong> and <strong>link</strong>. Name is displayed to the user by using <strong><em>getName()</em></strong>. Now I want to implement the onClicklistener such that new activity will open based on the position and equivalent url i.e <strong><em>getLink()</em></strong> of same position and sent it to next activity as extras.</p>
  
  <p>Here is my listview adapter</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class ListViewAdapter extends ArrayAdapter&lt;Hero&gt; {
  
      //the hero list that will be displayed
      private List&lt;Hero&gt; heroList;
  
      //the context object
      private Context mCtx;
  
      //here we are getting the herolist and context
      //so while creating the object of this adapter class we need to give herolist and context
      public ListViewAdapter(List&lt;Hero&gt; heroList, Context mCtx) {
          super(mCtx, R.layout.vault_list, heroList);
          this.heroList = heroList;
          this.mCtx = mCtx;
      }
  
      //this method will return the list item
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          //getting the layoutinflater
          LayoutInflater inflater = LayoutInflater.from(mCtx);
  
          //creating a view with our xml layout
          View listViewItem = inflater.inflate(R.layout.vault_list, null, true);
  
          //getting text views
          Button btn_one = listViewItem.findViewById(R.id.btn_one);
       
  
          //Getting the hero for the specified position
          Hero hero = heroList.get(position);
  
          //setting hero values to textviews
          btn_one.setText(hero.getName());
         
  
          //returning the listitem
          return listViewItem;
      }</code></pre>
  </div>
  </div>
  </p>