android - How to control indeterminante ProgressBar which is not part of a ListView? -



android - How to control indeterminante ProgressBar which is not part of a ListView? -

there , indeterminate progressbar rotates until listview content ready shown. both progressbar , listview part of same fragment.

so coded progressbar made visisble , gone asynctask fetches content.

mprogressbar = (progressbar) view.findviewbyid(r.id.progressbar); mprogressbar.getindeterminatedrawable() .setcolorfilter(getresources().getcolor(r.color.pink), porterduff.mode.multiply); new myasynctask().execute(); //then in asynctask private class myasynctask extends asynctask<void, integer, myadapter> { @override protected void onpreexecute() { mprogressbar.setvisibility(view.visible); } @override protected myadapter doinbackground(void... params) { //do stuff , homecoming loaded adapter homecoming adapter; } @override protected void onpostexecute(myadapter adapter) { mprogressbar.setvisibility(view.gone); } }

however progressbar is frozen , not spin?!

i tried instantiating progressbar onpreexecute, outer progressbar not take parameteres set within asynctask. can see because appears default color instead custom.

so how can command progressbar? right need show when content starts loading, , hide when it's ready shown.

note: don't need progressbar within each item, need way described.

have tried create constructor myasynctask , give progressbar parameter?

you can save private attributes within in other java class.

edit: define custom handler , phone call activity, playing visibility of progressbar.

public final class loadingdialoghandler extends handler { private final weakreference<activity> mactivity; // constants hiding/showing loading dialog public static final int hide_loading_dialog = 0; public static final int show_loading_dialog = 1; private view mloadingdialogcontainer; public loadingdialoghandler(activity activity, view container) { mactivity = new weakreference<activity>(activity); mloadingdialogcontainer = container; } public void handlemessage(message msg) { activity activity = mactivity.get(); if (activity == null) { return; } if (msg.what == show_loading_dialog) { mloadingdialogcontainer.setvisibility(view.visible); } else if (msg.what == hide_loading_dialog) { mloadingdialogcontainer.setvisibility(view.gone); } }

}

and phone call this:

in activity/fragment declare handle associate progress bar:

loadingdialoghandler loadingdialoghandler = new loadingdialoghandler(youractivity, findviewbyid(r.id.loading_indicator));

to show/hide (sample of showing):

loadingdialoghandler.sendemptymessage(loadingdialoghandler.show);

ps: maybe have run in uithread this:

activity.runonuithread(new runnable() { public void run() { //update progressbar } });

android android-listview android-asynctask android-progressbar

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -