How to change the text attribute of widget during run-time, android? -
hi i'm trying create layout dynamically based on info model. have problem doing that. xml file have here:
<?xml version="1.0" encoding="utf-8"?> <relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="#f9f9ff"> <textview android:layout_width="97dp" android:layout_height="33dp" android:id="@+id/textview" android:layout_alignparentleft="true" android:layout_marginleft="15dp" android:layout_alignparenttop="true" android:layout_margintop="19dp"/> </relativelayout>
this named dynamic.xml
. , i'm trying inflate layout @ run-time. i'm doing:
viewgroup parent = (viewgroup) findviewbyid(r.id.vertical_container); //getting textview , edittext view. layoutinflater inflater = this.getlayoutinflater(); view currentview = inflater.inflate(r.layout.dynamic,null); textview textview = (textview) currentview.findviewbyid(r.id.textview); //trying alter attributes. #fails! textview.settext("setting text code"); textview.setid(3); //setting view view = layoutinflater.from(getbasecontext()).inflate(r.layout.dynamic, null); parent.addview(view);
but doesn't seems working! line :
textview.settext("setting text code");
doesn't work. can see empty text in emulator not text setting text code
. not sure i'm making mistake. changes made in code not seen in emulator.
i can see dynamic
xml layout rendered attributes specified!
not sure i'm making mistake. possible accomplish i'm doing here? in advance.
i think setting wrong view getting result .no need of twice inflation of layout
//getting textview , edittext view. layoutinflater inflater = this.getlayoutinflater(); view currentview = inflater.inflate(r.layout.dynamic,null); textview textview = (textview) currentview.findviewbyid(r.id.textview); //trying alter attributes. #fails! textview.settext("setting text code"); textview.setid(3); //now had customize textview .now add together customize view view //setting view parent.addview(currentview);
android android-layout
No comments:
Post a Comment