android - can't modify layout defined in layout.xml at runtime (nullPointerException) -
i can't add sub-layout main layout of activity @ runtime. more precisely null pointer exception when call setcontentview(layout) or layout.add(mysublayout), layout retrieved findviewbyid(r.id.idlay). below here there xml code.
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/idlay" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillviewport="true" tools:context=".trainingacty" >
seems not possible modify layout created statically. see answers on stack overflow seems possible doing want, , i've never read in documentation of android nothing impossibility of it.
it possible modify layout @ runtime regardless of how created. here's example of how it. assume in example layout posted in file main.xml
.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); viewgroup main = (viewgroup) findviewbyid(r.id.idlay); textview text = new textview(this); text.settext("this test!"); main.addview(text); }
this, of course, won't modify resource file, when inflate next time, you'll have run through steps again.
Comments
Post a Comment