Problem with setText() on custom CheckBox

by » Thu, 05 Mar 2009 07:13:29 GMT

Sponsored Links

I've implemented a custom CheckBox view and faced a probelm with
adding text to it.

Here's my implementation:

public class MyCheckBox extends CheckBox{

private int imgResourceFocusedChecked, imgResourceFocusedNotChecked,
imgResourceNotFocusedChecked, imgResourceNotFocusedNotChecked;

        public MyCheckBox(Context context){

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

        public MyCheckBox(Context context, AttributeSet attrs, int defStyle)
                super(context, attrs, defStyle);

        private void init(AttributeSet attrs){
                TypedArray a = getContext().obtainStyledAttributes(attrs,
                imgResourceFocusedChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxFocusedChecked, -1);
                imgResourceFocusedNotChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxFocusedNotChecked, -1);
                imgResourceNotFocusedChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxNotFocusedChecked, -1);
                imgResourceNotFocusedNotChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxNotFocusedNotChecked, -1);
                strResourceText = a.getResourceId
(R.styleable.MyCheckBox_checkboxText, -1);

        public void onDraw(Canvas canvas){
                if (this.isChecked()){
                        if (this.isFocused()){
                        } else {
                } else {
                        if (this.isFocused()){
                        } else {

Then from my layout xml I do something like:

        android:text="This is a check box."

However, the text never comes up. Using the same technique with Button
and EditText views works fine , but not with check boxes. Hope to get
an advice of how to implement the proper behaviour. Thanks!


Other Threads

1. Horay dapat juga doc to go full gratisan

Malam suhu semua, setelah googling akhirnya ane dapat juga doc to go full, 
mayan buat edit naskah...kalo ada yg mau imel aja ya hehe, barangkali ada yg 
belum punya gitu hehe...salam dari nuwbie

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

"Indonesian Android Community [id-android]" 

2. Avoid non-static inner classes in an activity?

Since I seem to have caught two activity references in a heapdump,
where the Activity is set to singleTask.

Romain's advice on avoiding memory leaks includes:

"Avoid non-static inner classes in an activity if you don't control
their life cycle, use a static inner class and make a weak reference
to the activity inside"

What does this mean exactly? I can't find any examples, positive, or
negative for this rule.

I do have some non static inner classes in my activity.

Most of them are anonymous inner classes like this one. I see hundreds
of them in the samples:

        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Title progress is in range 0..10000
                setSecondaryProgress(100 *

Are anonymous inner classes okay?

I also see something like this in the samples:

    private OnClickListener mStopRepeatingListener = new
OnClickListener() { . . .

Are member variables points to a non static anonymous inner class
okay? I might think so because a member variable's lifecycle is
controlled by the activity's lifecycle.

Or do I assume that all the API samples leak a lot of contexts?

Thanks for any insights



3. Tampilan di Galaxy Spica

4. review singkat samdroidkitchen beta3

5. The linked program is no longer installed on the phone

6. ScrollView and Programmatically Scrolling

7. The linked program is no longer installed on the phone