title: need help for on click listener for android custom ListView
body: <p>my app has custom ListView, each row contains checkbox ,edit text and 2 buttons. In the main xml layout file i have 1 submit button and listView. i want that, when i click on submit button, i should get all checked row position.I am new to android programming ,so plz help me my code is not working here is my code:</p>
  
  <p>main.xml</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="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;Button android:layout_height="wrap_content" 
  android:text="@string/button_submit" 
  android:layout_width="wrap_content" 
  android:id="@+id/main_submit_button" android:onClick="@string/button_submit"&gt;&lt;/Button&gt;
  
  &lt;ListView
  android:id="@+id/list_view"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>items.xml</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="vertical"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"&gt;
  
  
  &lt;LinearLayout android:layout_height="wrap_content"
    android:layout_width="fill_parent"&gt;
  
    &lt;TextView 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" android:layout_weight="1"
    android:id="@+id/items_name" 
    android:gravity="left"
    android:textStyle="bold" /&gt;
  
    &lt;CheckBox android:id="@+id/items_check"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:gravity="right"
           /&gt;
  
  &lt;/LinearLayout&gt;
  
  
   &lt;LinearLayout android:layout_height="wrap_content"
    android:layout_width="fill_parent"&gt;
  
    &lt;Button android:id="@+id/items_add_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
      android:gravity="left"
      android:text="@string/text_switcher_plus" /&gt;
  
     &lt;EditText android:digits="10" 
     android:textStyle="bold" android:gravity="left" 
     android:id="@+id/items_plates" android:layout_height="wrap_content" 
     android:layout_width="90dp"&gt;&lt;/EditText&gt;
  
  
    &lt;Button  android:layout_height="wrap_content"         
      android:layout_width="wrap_content"  
      android:id="@+id/items_minus_button"
      android:text="@string/text_switcher_minus"
      android:gravity="right"
      /&gt;
  
  
       &lt;/LinearLayout&gt;
  
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>VegmenuActivity</p>
  
  <pre><code>package com.sagar.resmenu;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.util.SparseBooleanArray;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.Button;
  import android.widget.ListView;
  
    // reference:http://pareshnmayani.wordpress.com/tag/android-custom-listview-example
    public class VegmenuActivity extends Activity implements OnItemClickListener{
  
   //dynamic array that contains names of items
     private ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;
     (Arrays.asList("Veg pulav", "Pav bhaji", "Panir tikka", "veg kolhapuri",
             "Coconut Rice", "Curd rice", "Mint Pulao",
                           "Banana  Custard","Basundi", "Cheese potato Tikkis",
                            "Dum aloo"));
  
     private ArrayList&lt;Integer&gt; counter = new ArrayList&lt;Integer&gt;
                          (Arrays.asList(0, 0,0, 0, 0,0, 0,0, 0,0,0));
  
     private SparseBooleanArray a;
  
     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.main);
      final ListView lv =(ListView)findViewById(R.id.list_view);
    //  lv.setOnClickListener(null);
      MyAdapter adapter = new MyAdapter(getApplicationContext(),items,counter);
      lv.setAdapter(adapter);
      lv.setItemsCanFocus(false);    
      lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
      Button submit1;
      submit1 = (Button)findViewById(R.id.main_submit_button);
      submit1.setOnClickListener(new OnClickListener()
      {
      @Override
      public void onClick(View v)
      {
          a = new SparseBooleanArray();
          a.clear();
          a = lv.getCheckedItemPositions();
          int len = items.size();
  
          for (int i = 0; i &lt; len; i++)
          {
  
  
              if(a.valueAt(i) == true)
                  Log.d("Returned ", String.valueOf(a.valueAt(i)));
  
           }                
        }
      }); 
  
     }    
  
    //private OnItemClickListener selectCat = new OnItemClickListener();
     public void onItemClick(AdapterView&lt;?&gt; a, View v, int positon, long id) {
      // TODO Auto-generated method stub
            } 
  
    }
  </code></pre>
  
  <p>MyAdapter.java</p>
  
  <pre><code> package com.sagar.resmenu;
  
   import java.util.ArrayList;
  
   import android.content.Context;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.view.View.OnClickListener;
   import android.widget.BaseAdapter;
   import android.widget.Button;
   import android.widget.CheckBox;
   import android.widget.EditText;
   import android.widget.TextSwitcher;
   import android.widget.TextView;
  
  public class MyAdapter extends BaseAdapter implements OnClickListener{
    private LayoutInflater inflater;
    private ArrayList&lt;String&gt;  data;
    VegmenuActivity m;
    private ArrayList&lt;Integer&gt; counter;
  
   public MyAdapter(Context context, ArrayList&lt;String&gt; data,ArrayList&lt;Integer&gt; counter) {
      // TODO Auto-generated constructor stub
     super();
    // Caches the LayoutInflater for quicker use
     this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // Sets the events data
     this.data= data;
    this.counter=counter;   
    }
  
  
   public int getCount() {
      return this.data.size();
  //return this.counter.size();
    }
  
    public String getItem(int position) throws IndexOutOfBoundsException{
      return null;
    }
  
    public long getItemId(int position) throws IndexOutOfBoundsException{
      return 0;
    }
  
    public int getViewTypeCount(){
      return 1;
    }
  
    public static class ViewHolder   
      { 
  
  
          TextView items_name;
  
          CheckBox items_check ;
          Button items_plus_button;
          Button items_minus_button;
          EditText plates;
      }
  
  
    public View getView(int position, View convertView, ViewGroup parent){
       //String myText = getItem(position);          
       ViewHolder holder;
       if(convertView == null){ // If the View is not cached
          // Inflates the Common View from XML file
           holder = new ViewHolder();
          convertView = this.inflater.inflate(R.layout.items,parent,false);
  
          holder.items_name = (TextView) convertView.findViewById(R.id.items_name);
          holder.plates = (EditText) convertView.findViewById(R.id.items_plates);
          holder.items_check = (CheckBox) convertView.findViewById(R.id.items_check);      
  
         convertView.setTag(holder);
  
                  }
  
                  else           
                   holder=(ViewHolder)convertView.getTag();       
  
                   holder.items_name.setText(data.get(position));
                   holder.plates.setText(String.valueOf(counter.get(position)));
                  return convertView;
       }    
  
   @Override
   public void onClick(View arg0) {
      // TODO Auto-generated method stub
  
   }  
  
   }
  </code></pre>