|
Android example source code file (CheckableRelativeLayout.java)
The CheckableRelativeLayout.java Android example source codepackage com.example.android.rings_extended; import android.content.Context; import android.util.AttributeSet; 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 = { android.R.attr.state_checked }; public CheckableRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } public void toggle() { setChecked(!mChecked); } public boolean isChecked() { return mChecked; } public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } } Other Android examples (source code examples)Here is a short list of links related to this Android CheckableRelativeLayout.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.