Hi,
i'm wondering how i could enter the AttributeSet in the constructor of a class.
For example, i need to give in the AttributeSet attrs to load my attributes, but I don't know how this can be achieved in Basic4Android.
More like this:
Regards,
Tomas
EDIT: Ugh sorry, this should be in the developer questions thread...
i'm wondering how i could enter the AttributeSet in the constructor of a class.
B4X:
public MySwitch(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
Resources res = getResources();
mTextPaint.density = res.getDisplayMetrics().density;
mTextPaint.setShadowLayer(0.5f, 1.0f, 1.0f, Color.BLACK);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MySwitch, defStyle, 0);
mThumbDrawable = a.getDrawable(R.styleable.MySwitch_thumb);
mTrackDrawable = a.getDrawable(R.styleable.MySwitch_track);
mTextOn = a.getText(R.styleable.MySwitch_textOn);
mTextOff = a.getText(R.styleable.MySwitch_textOff);
mTextOutsideTrack = a.getBoolean(R.styleable.MySwitch_textOutsideTrack, false);
mTextOnThumb = a.getBoolean(R.styleable.MySwitch_textOnThumb, false);
mThumbTextPadding = a.getDimensionPixelSize( R.styleable.MySwitch_thumbTextPadding, 0);
mTrackTextPadding = a.getDimensionPixelSize( R.styleable.MySwitch_trackTextPadding, 0);
mSwitchMinWidth = a.getDimensionPixelSize( R.styleable.MySwitch_switchMinWidth, 0);
mSwitchMinHeight = a.getDimensionPixelSize( R.styleable.MySwitch_switchMinHeight, 0);
mSwitchPadding = a.getDimensionPixelSize( R.styleable.MySwitch_switchPadding, 0);
mTrackDrawable.getPadding(mTrackPaddingRect) ;
//Log.d(TAG, "mTrackPaddingRect=" + mTrackPaddingRect);
mThumbDrawable.getPadding(mThumbPaddingRect);
//Log.d(TAG, "mThumbPaddingRect=" + mTrackPaddingRect);
int appearance = a.getResourceId(R.styleable.MySwitch_switchTextAppearanceAttrib, 0);
if (appearance != 0) {
setSwitchTextAppearance(context, appearance);
}
a.recycle();
ViewConfiguration config = ViewConfiguration.get(context);
mTouchSlop = config.getScaledTouchSlop();
mMinFlingVelocity = config.getScaledMinimumFlingVelocity();
// Refresh display with current params
refreshDrawableState();
setChecked(isChecked());
this.setClickable(true);
//this.setOnClickListener(clickListener);
}
For example, i need to give in the AttributeSet attrs to load my attributes, but I don't know how this can be achieved in Basic4Android.
More like this:
B4X:
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MySwitch, defStyle, 0);
mThumbDrawable = a.getDrawable(R.styleable.MySwitch_thumb);
mTrackDrawable = a.getDrawable(R.styleable.MySwitch_track);
Regards,
Tomas
EDIT: Ugh sorry, this should be in the developer questions thread...
Last edited: