android - How do I set an id for an element xml in Java class? -


this question has answer here:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     relativelayout layout=(relativelayout) findviewbyid(r.id.rlt);     textview txtv=new textview(this);//i want set id element     txtv.settext("my text");     layout.addview(txtv); } 

i want set id txtv. and.. how change other attributes of element ?

you can set id calling setid.

public final static int my_id = 2;  textview tv = new textview(this); tv.setid(my_id); 

you can set attributes using whatever attribute name is. see textview documentation.

tv.settext("some text"); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -