2012-10-10 31 views
0

更新我在我使用的是相同的代碼添加,更新兩項活動,並與AlertDialog刪除。現在我想在類文件中編寫該代碼,然後從我的活動中訪問該函數。我也希望UI只有在函數完成執行後才能更新。桂是前函數執行完畢

我已經打過電話類文件像

Contact_update c=new Contact_update(context); 
c.delete(); 
myactivityfunction_gui_update(); 

的功能,但問題是,在完成功能之前myactivityfunction_gui_update();的執行獲取調用我的活動,所以我不能得到更新結果。有誰能告訴我什麼是正確的方法?

+1

只需撥打你的GUI更新功能** **後無論你在做什麼 – njzk2

+1

刪除功能是否使用單獨的線程? – waqaslam

+0

不是線程,而是使用數據庫類和手機的數據庫 – Nency

回答

0

您可以使用Asynctask。 保留所有加載更新功能在這樣的班級,

public Class A{ 

    A(Variables){ 
    } 
    int method A(){ 
    return int data 
    } 
. 
. 
. 
int method Z(){ 
return int data 
} 

} 

//您的活動

創建的AsyncTask功能

new AsyncTask<Void, Void, Void>() { 




      @Override 
      protected void onPostExecute(Void result) { 
       super.onPostExecute(result); 
// dismiss progress bar and call your GUi update function call here 
      } 

      @Override 
      protected void onPreExecute() { 

//Show progress bar    
super.onPreExecute(); 
      } 

      @Override 
      protected Void doInBackground(Void... params) { 

// Your time consuming function call 
int c=new A.method() 

       return null; 
      } 


     }.execute(); 
+0

但是如果在調用函數後你在int後面執行了int c = new A.method(),我們需要通過數據庫查詢而不是函數返回data.then來更新這個fillup的listview,然後在那個listview更新函數將會寫?在後 在做背景的postExecute方法執行 – Nency

+0

如果您正在使用列表視圖,建立在你的類A中的函數將返回的值在ArrayList中 T可以是類或數據類型,調用該函數,現在只是用返回的數據初始化ListView的適配器,並重置ListView ..... – Rs9766

相關問題