android - Getting TextView view object from "onCreate" Activity's method -
i'm having trouble on trying retrieve textview object id inside oncreate method activity.
my activity's xml fragment textview's section:
<textview android:id="@+id/message_display_field" android:layout_width="fill_parent" android:layout_height="wrap_content" />
the oncreate method:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_display_message); if (savedinstancestate == null) { getfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } intent intent = getintent(); string message = intent.getstringextra(mainactivity.extra_message); // create text view textview tv = (textview) findviewbyid(r.id.message_display_field); tv.settext(message); }
textview tv = (textview) findviewbyid(r.id.message_display_field);
not return textview expect return null instead
finally 1 expect, throws nullpointerexception
.
then how retrieve textview view object if not way go ? :(
notes :
there no warnning or error before press run button launch application through emulator.
nullpointer fired @ runtime.
i appriciate help, thank in advance !
actually if textview inside fragment xml u have :
1- go class fragment override oncreateview method there view inside fragment so.
textview foo;as //globle var @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); foo = rootview.findviewbyid(r.id.message_display_field); return rootview; }
now happy
hope helps
Comments
Post a Comment