package com.androidhub.core;

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

public class CheckableLinearLayout extends LinearLayout implements Checkable {
 private boolean checked = false;

 public CheckableLinearLayout(Context context) {
     super(context, null);
 }

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

 private static final int[] CheckedStateSet = {
     android.R.attr.state_checked
 };

 public void setChecked(boolean b) {
     checked = b;
 }

 public boolean isChecked() {
     return checked;
 }

 public void toggle() {
     checked = !checked;
 }

 @Override
 protected int[] onCreateDrawableState(int extraSpace) {
     final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
     if (isChecked()) {
         mergeDrawableStates(drawableState, CheckedStateSet);
     }
     return drawableState;
 }

 @Override
 public boolean performClick() {
     toggle();
     return super.performClick();
 }
}

Add a code snippet to your website: www.paste.org