worked
worked

Reputation: 5880

Android + Inflate layout within Custom Button

I need every instance of a custom Button to use a FrameLayout as it's layout. How do I do this from my custom Button class, as to avoid having to wrap every xml defined CustomButton in a FrameLayout?

public CustomButton(Context context) {
    super(context);
    init(context);
}

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

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

private void init(Context context) {
//this doesn't work...
    FrameLayout layout = new FrameLayout(context);
    inflate(context, R.layout.frame_layout, null);        
}

Upvotes: 0

Views: 298

Answers (1)

momor10
momor10

Reputation: 498

just put your FrameLayout arount your Custom button in frame_layout and later in other xml you can put it in as and this view will be as it is in frame_layout

Upvotes: 1

Related Questions