ListView with checkbox, select all button and none

0

I have a listview with check box

I'mlookingtoputacheckboxonthelist.ThenwhenIselectit,IwanttoselecteverythingfromthelistandwhenIclicktotaketheselectionIwanttotaketheselectionfromthewholelist.

Howtodothis?

ThisistheXMLthatI'vecreatedtobethelayoutofeachlistitem

<CheckBoxandroid:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:text="CheckBox" />

<TextView
    android:id="@+id/code"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/checkBox1"
    android:layout_alignBottom="@+id/checkBox1"
    android:layout_toRightOf="@+id/checkBox1"
    android:text="TextView" />

Here I set the adapter, the list passed as parameter has the name and the number of the recipient.

    dataAdapter = new MyCustomAdapter(this,R.layout.item_list_info, lista);
    ListView listView = (ListView) findViewById(R.id.lista);
    listView.setAdapter(dataAdapter);
    
asked by anonymous 18.11.2014 / 21:28

1 answer

1

Just create a layout with checkbox and place before the list. And by clicking on this checkbox for all checkbox a true on your MyCustomAdapter :

novacheckbox.onclick()
{
    int item=0;
    while ( item < dataAdapter.getCount() )
    {
         listView.setItemChecked(item, true);
         item++;
    }
} 
    
18.11.2014 / 21:39