android - How do I set an id for an element xml in Java class? -
this question has answer here:
- dynamic element id setid(int) - android 3 answers
@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
Post a Comment