Created
May 23, 2010 00:05
-
-
Save tokudu/410479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ABSOLUTELY AWESOME! THANK YOU FOR CREATING THIS! YOU ROCK!