Hi All

 i have  written a class  for customized Button.... this  is my code


package com.games.speedtester;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageButton;

public class Image_Only_Button extends ImageButton {

        int imageResourceNotFocused, imageResourceFocused, tx;
        String text;

        public Image_Only_Button(Context context) {
                super(context);

                throw new RuntimeException(
                                "Valid image resource IDs must be passed to 
this class via the XML
"
                                                + "parameters: 
pj:resourceNotFocused & pj:resourceFocused.");
        }

        public Image_Only_Button(Context context, AttributeSet attrs) {
                super(context, attrs);
                init(attrs);

        }

        public Image_Only_Button(Context context, AttributeSet attrs, int
defStyle) {
                super(context, attrs, defStyle);
                init(attrs);

        }

        private void init(AttributeSet attrs) {
                Log.i("test", "i have been called init()");

                TypedArray a = getContext().obtainStyledAttributes(attrs,
                                R.styleable.ImageOnlyButton);
                imageResourceFocused = a.getResourceId(
                                R.styleable.ImageOnlyButton_resourcePressed, 
-1);
                imageResourceNotFocused = a.getResourceId(
                                R.styleable.ImageOnlyButton_resourceNotPressed, 
-1);

        }

        public void onDrawBackground(Canvas canvas) {
                // Override this method & do nothing. This prevents the
                // parent.onDrawBackground(canvas)
                // from drawing the button's background.
        }

        @Override
        public void onDraw(Canvas canvas) {

                Log.i("SpeedTester", "Image_Only_Button called");
                if (isPressed()) {

                        setBackgroundResource(imageResourceFocused);
                        return;

                }
                if (!(isPressed())) {

                        setBackgroundResource(imageResourceNotFocused);
                        return;
                }
                super.onDraw(canvas);
        }
}

   i have took two images for showing "Pressed" and "UnPressed" mode,
but the problem is the image is not getting changed when  i pressed
the button( i think it has to change the image when  i press the
Button)

so guys can one tell where the problem is.... ??


Thanks in Advance for any Replays....!!!


Cheers
Imran
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to