AsyncTask 完成后如何显示弹出窗口?
How to showPopupWindow after AsyncTask finished?
我想在点击View时弹出Window一个textView,但是计算需要时间,所以我在AsyncTask中计算,但是如何立即显示弹出Window AsyncTask 进程完成后?
public void onClick(View widget) {
MyAsyncTask asyncTask = new MyAsyncTask(new AsyncResponse() {
@Override
public void processFinish(Object output) {
meaning_result = (String) output;
}
});
asyncTask.execute("xxxxx");
showPopupWindow(widget);
}
这是我的第一个想法,但 showPopupWindow(widget)
先执行而 meaning_result
尚未分配。如何让 showPopupWindow(widget)
在分配 meaning_result 后运行?
尝试这样的事情:
public void showPopUp(final View widget){
runOnUiThread(new Runnable() {
@Override
public void run() {
showPopupWindow(widget);
}
});
}
和:
public void onClick(final View widget) {
MyAsyncTask asyncTask = new MyAsyncTask(new AsyncResponse() {
@Override
public void processFinish(Object output) {
meaning_result = (String) output;
showPopUp(widget);
}
});
asyncTask.execute("xxxxx");
}
希望对您有所帮助
您需要在 AsynTask 的 postExecute 中显示弹出窗口。
public void onClick(View widget) {
AsyncTask asyncTask = new AsyncTask(){
@Override
protected long doInBackground(){
//Do your cacultation
}
@Override
protected void onPostExecute(Long result) {
showPopupWindow(widget);
}
});
asyncTask.execute("xxxxx");
}
我想在点击View时弹出Window一个textView,但是计算需要时间,所以我在AsyncTask中计算,但是如何立即显示弹出Window AsyncTask 进程完成后?
public void onClick(View widget) {
MyAsyncTask asyncTask = new MyAsyncTask(new AsyncResponse() {
@Override
public void processFinish(Object output) {
meaning_result = (String) output;
}
});
asyncTask.execute("xxxxx");
showPopupWindow(widget);
}
这是我的第一个想法,但 showPopupWindow(widget)
先执行而 meaning_result
尚未分配。如何让 showPopupWindow(widget)
在分配 meaning_result 后运行?
尝试这样的事情:
public void showPopUp(final View widget){
runOnUiThread(new Runnable() {
@Override
public void run() {
showPopupWindow(widget);
}
});
}
和:
public void onClick(final View widget) {
MyAsyncTask asyncTask = new MyAsyncTask(new AsyncResponse() {
@Override
public void processFinish(Object output) {
meaning_result = (String) output;
showPopUp(widget);
}
});
asyncTask.execute("xxxxx");
}
希望对您有所帮助
您需要在 AsynTask 的 postExecute 中显示弹出窗口。
public void onClick(View widget) {
AsyncTask asyncTask = new AsyncTask(){
@Override
protected long doInBackground(){
//Do your cacultation
}
@Override
protected void onPostExecute(Long result) {
showPopupWindow(widget);
}
});
asyncTask.execute("xxxxx");
}