android - ProgressDialog shown behind another dialog -
my custom dialog has list takes long time obtain. load in separate thread launched in onpreparedialog using asynctask. prior calling asynctask.execute invoke progressdialog. problem when dialog called first time (oncreatedialog invoked), progressdialog shown behind (empty) dialog. how can show progressdialog in hr front? when dialog dismissed , shown again, display order correct.
public class myactivity extends activity { fileselectdlg fileselectdlg = null; layoutinflater inflater; arraylist<string> filelist; @override public void oncreate(bundle savedinstancestate) { inflater = layoutinflater.from(this); } @override protected dialog oncreatedialog( int id ) { fileselectdlg = new fileselectdlg( ); return fileselectdlg; } @override protected synchronized void onpreparedialog( int id, dialog dialog ) { fileselectdlg.update_dlg_view( -1 ); } public class fileselectdlg extends dialog { private context context; private baseadapter adapter; public fileselectdlg( context context ) { super(context); this.context = context; view content = inflater.inflate( r.layout.file_select, null ); setcontentview( content ); adapter = new baseadapter() { @override public int getcount() { if( filelist != null ) return filelist.size(); return 0; } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview( int position, view convertview, viewgroup parent ) { textview textview; if (convertview == null) { convertview = inflater.inflate(r.layout.file_select_item, null); textview = (textview) convertview.findviewbyid(r.id.item_text); convertview.settag(textview); } else { textview = (textview)convertview.gettag(); } if( filelist != null ) { textview.settext( filelist.get( position ) ); } return convertview; } }; listview listview = (listview)findviewbyid( r.id.list ); listview.setadapter(adapter); listview.setonitemclicklistener( new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int clicked, long id ) { update_dlg_view( clicked ); } }); } public void update_dlg_view( int clicked ) { int option = option_get_list; string item = null; if( clicked >= 0 ) { item = filelist.get( clicked ); fileselector.setdir(item); } final progressdialog progressdialog = new progressdialog( context ); progressdialog.setmessage( "wait..." ); progressdialog.setcancelable(false); progressdialog.show(); new asynctask<integer, integer, long>() { protected long doinbackground( integer... _option ) { long option = _option[0]; filelist = fileselector.getlist(); return option; } @override protected void onpostexecute( long option ) { progressdialog.dismiss(); fileselectdlg.this.settitle( fileselector.getcurrentpath() ); adapter.notifydatasetchanged(); } }.execute(option); } }
try calling asynctask.execute inside oncreatedialog custom dialogue.
Comments
Post a Comment