package com.ternaryop.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Checkable;
import android.widget.RelativeLayout;

/**
 * Used to select items in listView
 * @author dave
 *
 */
public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
	private boolean isChecked;

	public CheckableRelativeLayout(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}

	public CheckableRelativeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public CheckableRelativeLayout(Context context, int checkableId) {
		super(context);
	}

	public boolean isChecked() {
		return isChecked;
	}

	public void setChecked(boolean isChecked) {
		this.isChecked = isChecked;
		setSelected(isChecked);
	}

	public void toggle() {
		setChecked(!isChecked);
	}
}
@@ -24,16 +24,68 @@
 idget;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import a
@@ -142,16 +142,73 @@
 uteSet;%0A
+import android.view.View;%0Aimport android.view.ViewGroup;%0A
 import a
@@ -311,16 +311,20 @@
 istView%0A
+ * %0A
  * @auth
@@ -333,16 +333,17 @@
  dave%0A *
+ 
 %0A */%0Apub
@@ -422,17 +422,20 @@
 kable %7B%0A
-%09
+    
 private 
@@ -453,18 +453,65 @@
 hecked;%0A
-%0A%09
+    private List%3CCheckable%3E checkableViews;%0A%0A    
 public C
@@ -573,12 +573,9 @@
 trs,
-%0A%09%09%09
+ 
 int 
@@ -582,26 +582,32 @@
 defStyle) %7B%0A
-%09%09
+        
 super(contex
@@ -627,21 +627,43 @@
 Style);%0A
-%09%7D%0A%0A%09
+        init();%0A    %7D%0A%0A    
 public C
@@ -720,26 +720,32 @@
 et attrs) %7B%0A
-%09%09
+        
 super(contex
@@ -755,21 +755,43 @@
 attrs);%0A
-%09%7D%0A%0A%09
+        init();%0A    %7D%0A%0A    
 public C
@@ -849,18 +849,24 @@
 leId) %7B%0A
-%09%09
+        
 super(co
@@ -873,21 +873,129 @@
 ntext);%0A
-%09%7D%0A%0A%09
+        init();%0A    %7D%0A%0A    private void init() %7B%0A        checkableViews = new ArrayList%3CCheckable%3E();%0A    %7D%0A%0A    
 public b
@@ -1015,18 +1015,24 @@
 ked() %7B%0A
-%09%09
+        
 return i
@@ -1041,21 +1041,27 @@
 hecked;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public v
@@ -1087,28 +1087,212 @@
 ean 
-isChecked) %7B%0A%09%09this.
+checked) %7B%0A        isChecked = checked;%0A        setSelected(isChecked);%0A        for (Checkable c : checkableViews) %7B%0A            c.setChecked(checked);%0A        %7D%0A    %7D%0A%0A    public void toggle() %7B%0A        
 isCh
@@ -1299,16 +1299,17 @@
 ecked = 
+!
 isChecke
@@ -1311,18 +1311,24 @@
 hecked;%0A
-%09%09
+        
 setSelec
@@ -1347,62 +1347,772 @@
 d);%0A
-%09%7D%0A%0A%09public void toggle() %7B%0A%09%09setChecked(!isChecked);%0A%09
+        for (Checkable c : checkableViews) %7B%0A            c.toggle();%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected void onFinishInflate() %7B%0A        super.onFinishInflate();%0A        final int childCount = this.getChildCount();%0A        for (int i = 0; i %3C childCount; ++i) %7B%0A            findCheckableChildren(this.getChildAt(i));%0A        %7D%0A    %7D%0A%0A    private void findCheckableChildren(View v) %7B%0A        if (v instanceof Checkable) %7B%0A            checkableViews.add((Checkable) v);%0A        %7D%0A        if (v instanceof ViewGroup) %7B%0A            final ViewGroup vg = (ViewGroup) v;%0A            final int childCount = vg.getChildCount();%0A            for (int i = 0; i %3C childCount; ++i) %7B%0A                findCheckableChildren(vg.getChildAt(i));%0A            %7D%0A        %7D%0A    
 %7D%0A%7D

Set checked state for Checkable children