I'm a bit late to the party ... but anyway you can do it from xml if you use api level 21 or higher. I'm not sure if the memory leak problem is still present or not.
<Button android:layout_width=match_parent android:layout_height=wrap_content android:text="New button" > <tag android:id="SomeId" android:value="SomeValue" /> </Button>
psykid
source share