android - How to perform commands after "setContentView" is being called -


i'm using "include" on main layout. each 1 of them relativelayout needs onclick listener attached, , update information related. i've tried by:

setcontentview(r.layout.allobjects);     objectlisteners objectlisteners = new objectlisteners(objects);     for(int i=0;i<1;i++)     {                    relativelayout objectboxrelativelayout = (relativelayout)findviewbyid(r.id.object1 + i);                     objectboxrelativelayout.setonclicklistener(objectlisteners.getobjectlistener(i));         someobject currentobject = this.objects.get(i);          object viewobject = findviewbyid(r.id.object1 + i);         this.setobjectview(viewobject, currentobject);               }  

the issue takes long after "setcontentview(r.layout.allobjects);" command, , application shows black screen until finish loading. in addition, use "setcontentview(r.layout.allobjects);" after perform above commands. of these commands have written after "setcontentview(r.layout.allobjects);".

how can handle kind of situation ? have use onpreexecute , implement asynctask ?

yes, asynctask solution show loading dialog while these commands being executed.

update:

add class under oncreate() function:

 private class mytask extends asynctask<void, void, void> {              private progressdialog dialog;             private context context;              public mytask(activity activity) {                 context = activity;                 dialog = new progressdialog(context);             }              protected void onpreexecute() {                 dialog.settitle("loading...");                 dialog.setmessage("loading...");                 dialog.show();              }              @override             protected void doinbackground(void... params) {             //do code here in background                protected void onpostexecute(void res) {                  dialog.dismiss();                 } } 

then use task inside oncreate() this:

    mytask mt = new mytask(this);     mt.execute(); 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -