ListView With Checkboxes have problem
<p>I implement a ListView with three columns, first is Textview, second is also TextView and third is CheckBox.</p>

<p>all thing do fine, it show exactly in Layout file as i want.</p>

<p>but two problems i faced</p>

<p>1) The checkBox checked or unchecked state is replaced automatically when i scroll the screen, to show full List.</p>

<p>2) listview.setOnItemClickListener(new OnItemClickListener(){}), this function is not calling.</p>

<p>I want to check a checkbox on click any of the item in listView</p>

<p>and then has a button to submit all checked state of listview, how i can do this</p>

<pre><code>listview=(ListView)findViewById(R.id.listview);
        // create the grid item mapping
        String[] from = new String[] {"col_1","col_2"};
        int[] to = new int[] { R.id.txtnameItem, R.id.txtpriceItem};

        // prepare the list of all records
        List&lt;HashMap&lt;String, String&gt;&gt; fillMaps = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
        for(int i = 0; i &lt;items.length; i++)
        {
            HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
            map.put("col_1",items[i]);
            map.put("col_2",price[i]);
            fillMaps.add(map);
        }
        SimpleAdapter adapter=new SimpleAdapter(this, fillMaps, R.layout.item, from, to);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parentView, View v, int position,long id) 
            {
                Log.d("Inside onClilck log","Yes");
                Toast.makeText(v.getContext(),""+position,Toast.LENGTH_LONG).show();
            }
        });
</code></pre>

<p><strong>item.xml file is</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:orientation="vertical"
  android:background="#FFFFFF"
  android:layout_height="fill_parent"&gt;
    &lt;LinearLayout
        android:layout_margin="15dip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="#FFFFFF"
        android:orientation="horizontal"
        android:id="@+id/linearLayout1"&gt;
        &lt;LinearLayout 
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_gravity="center"
            android:padding="5dip"
            android:paddingRight="0dip"
            android:id="@+id/linearLayout2"&gt;
            &lt;TextView
                android:id="@+id/txtnameItem"
                android:textSize="20px"
                android:textStyle="bold"
                android:text="col_1"
                android:gravity="left"
                android:textColor="#000000"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"&gt;
            &lt;/TextView&gt;
        &lt;/LinearLayout&gt;
        &lt;LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:textStyle="bold"
            android:id="@+id/linearLayout2"&gt;
            &lt;TextView
                android:id="@+id/txtpriceItem"
                android:gravity="left"
                android:layout_gravity="center"
                android:text="col_2"
                android:layout_weight="1"
                android:textSize="20px"
                android:textColor="#000000"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"&gt;
            &lt;/TextView&gt;
            &lt;CheckBox
                android:gravity="right"
                android:layout_weight="1"
                android:text=""
                android:textColor="#000000"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_gravity="right|center"
                android:checked="false"
                android:id="@+id/chkboxItem"&gt;
            &lt;/CheckBox&gt;
        &lt;/LinearLayout&gt;
    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p><strong>And finally main.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout android:id="@+id/main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"&gt;
    &lt;!-- Header --&gt;
    &lt;LinearLayout android:id="@+id/header"
        android:background="#FFFFFF"
        android:padding="10dip"
        android:orientation="horizontal"
        android:paddingBottom="5dip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        &gt;
        &lt;TextView android:id="@+id/heading"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="Items"
            android:gravity="left"
            android:layout_weight="1"
            android:textColor="#CC6633"
            android:textSize="25px"
            android:textStyle="bold"
        /&gt;
        &lt;Button
            android:text="Add To Order"
            android:id="@+id/btnOrder"
            android:layout_weight="1"
            android:textSize="15px"
            android:gravity="right"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"&gt;
        &lt;/Button&gt;
    &lt;/LinearLayout&gt;
    &lt;LinearLayout android:id="@+id/header"
        android:background="#FFFFFF"
        android:padding="5dip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        &gt;
        &lt;LinearLayout 
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_gravity="center"
            android:padding="5dip"
            android:id="@+id/linearLayout2"&gt;
            &lt;TextView
                android:id="@+id/txtnameItem"
                android:text="Name"
                android:gravity="left"
                android:textColor="#000000"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"&gt;
            &lt;/TextView&gt;
        &lt;/LinearLayout&gt;
        &lt;LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:padding="5dip"
            android:gravity="left"
            android:id="@+id/linearLayout2"&gt;
            &lt;TextView
                android:id="@+id/txtpriceItem"
                android:gravity="left"
                android:text="Price"
                android:layout_weight="1"
                android:textColor="#000000"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_gravity="left"&gt;
            &lt;/TextView&gt;
            &lt;TextView
                android:id="@+id/txtorderItem"
                android:gravity="right"
                android:text="Order"
                android:layout_weight="1"
                android:textColor="#000000"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"&gt;
            &lt;/TextView&gt;
        &lt;/LinearLayout&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- List Divider --&gt;
    &lt;View android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:background="#C85A17" /&gt;

    &lt;!-- ListView (list_items) --&gt;
    &lt;LinearLayout android:id="@+id/layout"
        android:layout_width="fill_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content"&gt;
        &lt;ListView android:id="@+id/listview"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:layout_width="fill_parent"&gt;
        &lt;/ListView&gt;
    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>
