2011-12-24 35 views
0

我有一個ListActivity需要大量的數據通過Thread進行處理。我想在background中完成工作時顯示Dialog。但是,Dialog直到視圖加載完成纔會顯示。我在正常的activity上使用這種方法,它工作(Dialog彈出,工人開始,工人結束,Dialog解散)。工作完成後,會發送一條消息handler加載view並解除DialogListActivity和Dialogs

這裏是我的代碼:

@Override 
public void onCreate(Bundle icicle) { 

    super.onCreate(icicle); 
    initViewProperties(); 
    dialogCode = 0; 
    showDialog(dialogCode); 

} 

@Override 
protected Dialog onCreateDialog(int id) { 

    int resID = getResources().getIdentifier(getCfrFile(), "raw", getPackageName());   
    progDialog = new ProgressDialog(this); 

    switch (dialogCode) { 
     case 0: 
      progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
      progDialog.setMessage(getCurrentTitle()); 
      break; 
     case 1: 
      progDialog.setMessage("Loading CFR"); 
      break; 

     default: 
      break; 
    }  

    try { 
     // do the work here 
     xmlListRowFactoryHelper = new AcmListViewFactoryHelper(handler, resID, this, xpathBuilder(false), "title") ; 
     xmlListRowFactoryHelper.run(); 

    } catch (Exception e) { 

     e.printStackTrace(); 
    } 

    return progDialog; 

} 

final Handler handler = new Handler() { 
    @Override 
    public void handleMessage(Message msg) { 

     int total = msg.getData().getInt("total");    

     progDialog.setProgress(total); 

     if (total <= 0){ 

      xmlListRowFactoryHelper.setState(AcmTableRowFactoryHelper.DONE); 
      // load the view here 
      loadListView();  
     } 
    } 
} 

回答