Skip to content Skip to sidebar Skip to footer

How To Set Tag On A Button Programmatically

On the XML I can set my flag on android:tag, but how can I do it pro grammatically?

In code you can get/set the tag

Buttonbutton= (Button) findViewById(R.id.button);
// set tag
button.setTag("myFlag");

// get tagStringtag= (String) button.getTag(); 

Solution 2:

To set the Tag for a view call the view.setTag(tagvalue)

button1.setTag(1);

To get the Tag for a view call the view.getTag()

button1.getTag();

Post a Comment for "How To Set Tag On A Button Programmatically"