从AsyncTask的postexecute访问片段的方法 [英] Access fragment method from asynctask postexecute
问题描述
我需要一些帮助来管理片段和AsyncTask的,从来就搜索了很多在谷歌和这里的计算器,但我仍然不会产生积极的结果。
I need some help to manage fragments and asynctask, I´ve search a lot in google and here in stackoverflow but I didn´t get a positive result.
我有一个TabsActivity和三个选项卡(片段)的应用程序。其中之一是谷歌地图。我正尝试更新与get调用地图标记抛出一个自定义的请求类。
I have an app with a TabsActivity and three tabs (fragments). One of them is a google maps. I´m trying to update the markers in the map with a get call throw a custom request class.
问题是,我想从postexecute方法调用中的片段映射类的函数。我在asyntask的背景下,我试着也传递片段作为一个参数,但我不知道,即使在这样如何调用该函数。该AsyncTask的类文件(它isn't片段类中)。
The problem is that I want to call a function in the fragment map class from the postexecute method. I have the context in the asyntask, I tried also passing the fragment as a parameter but I don´t know even in that way how to call the function. The Asynctask class is a file (it isn´t inside the fragment class).
任何帮助将是preciated。
Any help will be apreciated.
问候。
Pd积 - 约对不起我的英语不好:))
P.D - sorry about my poor english :))
推荐答案
尝试通过你的片段到AsyncTask的是这样的:
Try passing your fragment to the AsyncTask like this:
class WorkerTask extends AsyncTask<Void, Void, Void> {
private MyMapFragment mapFragment;
WorkerTask(MyMapFragment mapFragment) {
this.mapFragment = mapFragment;
}
@Override
protected Void doInBackground(Void... params)
{
...
}
@Override
protected void onPostExecute(Void res)
{
mapFragment.updateStuff(...);
}
}
这篇关于从AsyncTask的postexecute访问片段的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!