【问题标题】:How To Get the Array Value from AsyncTask to other Method in Android Studio如何从 AsyncTask 获取数组值到 Android Studio 中的其他方法
【发布时间】:2020-04-26 14:40:53
【问题描述】:
大家好,现在我有一个 asyncTask 方法。在里面,我创建了一个数组并执行 for 循环来过滤数据。所以我的问题是,我怎样才能将最新的 Array 值传递给我的其他方法?
【问题讨论】:
标签:
java
arrays
android-studio
for-loop
【解决方案1】:
据我所知,要处理 AsyncTask,您可以使用用户界面,
使用回调方法创建接口:
public interface callBackListener {
void Responce(ArrayList data);
}
在你想拥有数组列表的Activity中:
用这个参数调用你的 asyncTask Method 并且 asyncTaskMethod 参数应该是 Type of (callBackListener callback) :
asyncTaskMethod(your_parameters, new callBackListener (){
@Override
public void Responce(ArrayList bundle) {
}
});
当你更新数组时,在你的 asyncTaskMethod 中调用:
callback.Response(arrayList);