0

我有两个活动,其中我使用相同的代码来添加、更新和删除AlertDialog。现在我想在类文件中编写该代码,然后从我的活动中访问该函数。我还希望UI仅在函数完成执行后更新。

我试过调用类文件的函数,比如

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

但问题是,在函数完成之前,执行 myactivityfunction_gui_update();被调用,所以我无法在我的活动中获得更新的结果。谁能告诉我正确的方法是什么?

4

1 回答 1

0

您可以使用异步任务。将所有添加更新功能保留在这样的类中,

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();
于 2012-10-12T10:04:07.367 回答