Skip to content

Instantly share code, notes, and snippets.

@tokudu
Created May 23, 2010 00:05
Show Gist options
  • Select an option

  • Save tokudu/410479 to your computer and use it in GitHub Desktop.

Select an option

Save tokudu/410479 to your computer and use it in GitHub Desktop.
package com.tokudu.begemot.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.CheckedTextView;
import android.widget.LinearLayout;
/*
* This class is useful for using inside of ListView that needs to have checkable items.
*/
public class CheckableLinearLayout extends LinearLayout implements Checkable {
private CheckedTextView _checkbox;
public CheckableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// find checked text view
int childCount = getChildCount();
for (int i = 0; i < childCount; ++i) {
View v = getChildAt(i);
if (v instanceof CheckedTextView) {
_checkbox = (CheckedTextView)v;
}
}
}
@Override
public boolean isChecked() {
return _checkbox != null ? _checkbox.isChecked() : false;
}
@Override
public void setChecked(boolean checked) {
if (_checkbox != null) {
_checkbox.setChecked(checked);
}
}
@Override
public void toggle() {
if (_checkbox != null) {
_checkbox.toggle();
}
}
}
@iOSDev33

Copy link
Copy Markdown

ABSOLUTELY AWESOME! THANK YOU FOR CREATING THIS! YOU ROCK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment