Listview with checkbox, select all and none button

Asked

Viewed 1,135 times

0

I have a listview with check box

I’m looking to put a checkbox on top of the list. So when I select it, I want to select everything from the list and when I click to take the selection I want to take the selection from the whole list.

How to do this?

This is the XML I created to be the layout of each item in the list

<CheckBox
    android: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 select the Adapter, the list passed as parameter has the name and number of the recipient.

    dataAdapter = new MyCustomAdapter(this,R.layout.item_list_info, lista);
    ListView listView = (ListView) findViewById(R.id.lista);
    listView.setAdapter(dataAdapter);

1 answer

1

Just create a layout with checkbox and put it before the list. And by clicking on this checkbox by all checkbox to true in your MyCustomAdapter:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.