Android Open Source - budget-envelopes Checkable Relative Layout

From Project

Back to project page budget-envelopes.


The source code is released under:

GNU General Public License

If you think the Android project budget-envelopes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

 * This file is a part of Budget with Envelopes.
 * Copyright 2013 Michael Howell <>
 *//  w  ww.ja  v  a 2 s .  co  m
 * Budget is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * Budget is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Budget. If not, see <>.

package com.notriddle.budget;

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

 * A special variation of RelativeLayout that can be used as a checkable object.
 * This allows it to be used as the top-level view of a list view item, which
 * also supports checking.  Otherwise, it works identically to a RelativeLayout.

public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
    private boolean mChecked;

    private static final int[] CHECKED_STATE_SET = {

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

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

    public void toggle() {
    public boolean isChecked() {
        return mChecked;

    public void setChecked(boolean checked) {
        if (mChecked != checked) {
            mChecked = checked;
            int s = getChildCount();
            for (int i = 0; i != s; ++i) {
                View v = getChildAt(i);
                if (v instanceof Checkable) {
                    Checkable c = (Checkable)v;

Java Source Code List