android - findViewByID(R.layout.skeleton_activity) returns null -
i trying register context menu in skeleton app's oncreate():
/** called activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // inflate our ui xml layout description. setcontentview(r.layout.skeleton_activity); view v = findviewbyid(r.layout.skeleton_activity); registerforcontextmenu(v); // find text editor view inside layout, because // want various programmatic things it. meditor = (edittext) findviewbyid(r.id.editor); // hook button presses appropriate event handler. ((button) findviewbyid(r.id.back)).setonclicklistener(mbacklistener); ((button) findviewbyid(r.id.clear)).setonclicklistener(mclearlistener); meditor.settext(gettext(r.string.main_label)); }
the debugger tells me findviewbyid(r.layout.skeleton_activity) returns null.
@commonsware solution similar post wait until onfinishinflate(). however, in sample project provides, doesn't seem waits until onfinishinflate.
my questions:
- can registerforcontextmenu() wait until onfinishinflate()?
- if so, how do so?
this line not correct asking id , providing layout
view v = findviewbyid(r.layout.skeleton_activity);
instead if want have object of root layout element provide id , try this
view v = findviewbyid(r.id.root_element);
Comments
Post a Comment