I have a dialog that contains listview with checkboxes and a button that becomes visible if at least one checkbox is checked. Click on the button removes checked lines from the listview. But in this dialog I have a strange behaviour of the checkboxes in the list. For instance, if the list contains four lines, and I check one of them no more items can be checked anymore. If I add more items into the list then I can check more than one, but if I remove some items, remaining items become uncheckable.
PS. Is there a way to fix or workaround it anyhow?
UPDATE1: I found out that checkboxes do not become absolutelly inactive and if to try to click one several times it can become checked. It looks like area around the check box that is recognized as onClick area is set too little.
UPDATE2: Also I found out that if I comment this line from the dialog initialization code
getWindow ().setLayout (LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
then all the checkboxes in the list become uncheckable right after dialog instantiation.
Dialog layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="200dip"
android:orientation="vertical"
android:background="@android:color/white"
>
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:divider="@color/list_divider"
android:dividerHeight="2px"
android:focusable="false"
android:clickable="false"
android:choiceMode="multipleChoice"
/>
<LinearLayout
android:id="@+id/buttons_pane"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
>
<Button
android:id="@+id/misc_list_remove_btn"
android:layout_width="fill_parent"
android:layout_height="48dip"
android:text="@string/remove"
/>
</LinearLayout>
</LinearLayout>
Item layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="47dip"
android:orientation="horizontal"
android:background="@android:color/white"
>
<CheckBox
android:id="@+id/misc_selectable_list_item_chk"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:checked="false"
/>
</LinearLayout>
I create the dialog this way
public ShowSelectableListDialog (Activity context, int titleId)
{
super (context);
setContentView (R.layout.misc_selectable_list_dlg);
setTitle (titleId);
getWindow ().setLayout (LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
adapter_ = setupListAdapter (getInitialValues (), context);
ListView listView = (ListView)findViewById (R.id.list_view);
listView.setAdapter (adapter_);
listView.setItemsCanFocus (false);
Button removeButton = (Button)findViewById (R.id.misc_list_remove_btn);
removeButton.setOnClickListener (this);
}
and item in the list
@Override
protected View instantiateView (Object ... params)
{
String title = (String)params[0];
CompoundButton.OnCheckedChangeListener checkedChangeListener =
(CompoundButton.OnCheckedChangeListener)params[1];
LayoutInflater inflater = Utils.getInflater (getContext ());
View view = inflater.inflate (R.layout.misc_selectable_list_item, null);
view.setId (title.hashCode ());
CheckBox chk = (CheckBox)view.findViewById (R.id.misc_selectable_list_item_chk);
chk.setText (title);
chk.setOnCheckedChangeListener (checkedChangeListener);
return view;
}