Android parsing styles for custom widget not working

I have created custom widget for my android application and i want to create custom styles for it. But while parsing it in the class returns always null. Gone through several links and couldn't figure out what the problem is ? Can anyone help ?

My atttr.xml is


    <declare-styleable name="Widget">
        <attr name="headers" format="reference" />
        <attr name="height" format="integer" />


Widget class

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

    TypedArray attr = context.obtainStyledAttributes(attrs,
    String[] columns = (String[]) attr

    int height = attr.getInt(R.styleable.Widget_height, 0);

And the layout file

<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        widget:headers="@array/headers" >

Arrays.xml is


    <string-array name="headers">



did you try recycling the array at the end of view constructor? this link covers most of stuff - creating custom views

After go through the several samples i figured out the problem.

Just replaced the line

TypedArray attr = context.obtainStyledAttributes(attrs,

with this

TypedArray attr = context.getTheme().obtainStyledAttributes(attrs,

Need Your Help

Using DataTrigger to apply different Views to the same ViewModel

wpf mvvm datatemplate datatrigger

I have a ViewModel where I created a bool DisplaySummary property. When this is true, a SummaryView is to be use to render that ViewModel, otherwise a DatailedView is to be used.

Random is returning the same output every time

c++ random vector

I wrote this code which is working fine but everytime the output is the same. So nothing random about it. Curious to know why!