android - When Fragment.onCreateView is complete and how to receive this event from the Activity? -


this question has answer here:

edit

changed title.

sdk guide document says, activity.oncreate complete after fragment.oncreateview , fragment.onacvitycreated.

but if try findviewbyid view of fragment returns null.

how can access contents of fragment?


i'm new android ui dev.

below sample code generated eclipse ide.

public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          if (savedinstancestate == null) {             getfragmentmanager().begintransaction().add(r.id.container, new placeholderfragment()).commit();              // null             view rootview = findviewbyid(r.id.txtview);         }     }      public static class placeholderfragment extends fragment {          public placeholderfragment() {         }          @override         public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {             view rootview = inflater.inflate(r.layout.fragment_main, container, false);             return rootview;         }     }  } 

first of all, want access inner contents of 'fragment_main'.
can findviewbyid?

i found calling findviewbyid view of fragment @ oncreate call not working.
how know when fragment views ready @ activity level?

i read how implement onfragmentinteractionlistener

am needed manually implement event listener this?

but if try findviewbyid view of fragment returns null. 

you can not access view of fragment in activity's oncreate or ever, can call view of fragment in activity.

i found calling findviewbyid view of fragment @ oncreate call not working. 

that because view not inflated yet in fragment returning null.

have @ fragment life cycle:

view ghazanfar abbas's profile on linkedin

as can see oncreate before oncreateview inflate view fragment's layout.

solution:

you call findviewbyidit in fragment's onactivitycreated.

sample:

@override     public void onactivitycreated(bundle savedinstancestate) {     super.onactivitycreated(savedinstancestate);      textview sample = (textview) getview().findviewbyid(your_id);     } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -