Jennifer
Jennifer

Reputation: 1852

How to Call the class that extends RelativeLayout programatically in android?

I've made a layout in java class by extending the RelativeLayout and want to call this view programatically when the button is clicked. I was able to set the custom layout in the xml file like this

<com.sample.CustomLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

I have set some sample of the code below

public class Card extends RelativeLayout {

    TextView tutorialok;

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

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

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

How will I call the this class when the button is clicked ? Since, I'm new to Android, some tips or code will be helpful !

Upvotes: 0

Views: 699

Answers (1)

koutuk
koutuk

Reputation: 832

//custom layout is called by fully Qualified name ... package.classname
<com.sample.card
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>

Upvotes: 1

Related Questions