title: How to get row position for the ListView when a button on the row pressed
body: <p>I have a simple list with 3 items including a button. I want to get the row number of the button. I am not able to get it work. Experts please help.</p>
  
  <p>Here is my activity</p>
  
  <pre><code>import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.Toast;
  
  
  public class MyListActivity extends ActionBarActivity implements AdapterView.OnItemClickListener{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.list_layout);
  
          ListView lv = (ListView) findViewById(R.id.listView);
          lv.setOnItemClickListener(this);
  
          String[] countries = new MyCountries().getCountries();
  
          ListAdapter la = new MyListAdapter(this, countries);
          lv.setAdapter(la);
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.list_menu, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
          Toast.makeText(this, "Clicked Position " + String.valueOf(position), Toast.LENGTH_SHORT).show();
      }
  
      public void onClick(View v)
      {
          View myView = v;
      }
  }
  </code></pre>
  
  <p>My list row</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:clickable="true"&gt;
  
      &lt;EditText
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:id="@+id/editText"
          android:layout_weight="1" /&gt;
  
      &lt;TextView
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Medium Text"
          android:id="@+id/textView"
          android:layout_weight="1" /&gt;
  
      &lt;Button
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:text="ClickMe"
          android:id="@+id/button"
          android:layout_gravity="right"
          android:layout_weight="1"
          android:onClick="onClick" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>List of countries</p>
  
  <p>package com.example.ananth.listviewexample;</p>
  
  <pre><code>import java.util.Locale;
  
  public class MyCountries {
  
      private String[] countries;
  
      public String[] getCountries() {
          String [] locales  = Locale.getISOCountries();
          countries = new String[locales.length];
          for (int i = 0; i &lt; locales.length; i ++)  {
  
              Locale obj = new Locale("", locales[i]);
  
              countries[i] = obj.getDisplayCountry();
  
          }        return countries;
      }
  
  
      public MyCountries()
      {
  
      }
  }
  </code></pre>
  
  <p>My list adapter</p>
  
  <pre><code>import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.content.Context;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  
  public class MyListAdapter extends ArrayAdapter &lt;String&gt; {
      private final Context context;
      private final String[] values;
  
      public MyListAdapter(Context context, String[] values) {
          super(context, R.layout.list_row, values);
          this.context = context;
          this.values = values;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View rowView = inflater.inflate(R.layout.list_row, parent, false);
          TextView textView = (TextView) rowView.findViewById(R.id.editText);
          textView.setText(values[position]);
  
          textView = (TextView) rowView.findViewById(R.id.textView);
          textView.setText(values[position]);
  
          return rowView;
      }
  }
  </code></pre>
  
  <p>I need to get the position either in onItemClick() or onClick()</p>
  
  <p>Thanks in advance.</p>
  
  <p>Adding OnClickListener() for each button while inflating would be overkill as I will have hundreds of rows.</p>