progressdialog - Android using Multiple Progress Dialogs -
i trying build class go web, download data , load database. have no problem doing single progress dialog can not figure out how have multiple dialogs. in researching this, found hundreds of progress dialog questions, not seem straight forward should be.
i have tried using handlers , threads cannot ma
i looking example of working code accomplish this.
here pseudo code attempting:
public class myactivity extends activity() { private webio webio ; // web acess io private dataio dataio ; // database io public void oncreate( bundle savedinstancestate ) { dataio = new dataio( ); webio = new webio(); dataio.open(); runprogram(); } } private void runprogram() { startprogressdialog( "downloading data web" ); new thread() { public void run() { try{ string vdata = webio.getdata(); dismissprogressdialog(); if ( vdata.length() > 0 ) { promptuser( vdata ); } } } } } private void promptuser( vdata ){ if alertdialog_to_prompt_user_to_load(){ { loaddata( pdata ) } private void loaddata( string pdata ){ startprogressdialog( "loading data database" ); new thread() { public void run() { try{ loaddataintodatabase(); dismissprogressdialog(); } } } } }
the way have multiple dialogs layer them on top of each other, obvious user experience no-no. in android, dialogs own window, there can 1 in focus @ time.
to solve problem, create custom dialog multiple progressbar
widgets. simplest way start dialogfragment
, override oncreateddialog()
return alertdialog
custom view. set custom view on alert dialog, see setview()
method on alertdialog
. e.g.,
@override public dialog oncreatedialog(bundle savedinstancestate) { layoutinflater li = layoutinflater.from(context); view layout = = li.inflate(r.layout.my_dialog); return new alertdialog.builder(getactivity()) .seticon(..) .settitle(...) .setview(layout) ... .create(); }
it'd pretty neat encapsulate multi-download progress dialog, register additional downloads , have class automatically add progress bar , register progress updates.
Comments
Post a Comment