如何从其他片段中调用片段中的AsyncTask?
片段中AsyncTask
的代码。
public class FileBrowserFragment extends Fragment {
private class ContiunedDownloadTask extends AsyncTask<FileBrowser, Integer, FileBrowser> {
@Override
protected FileBrowser doInBackground(FileBrowser... browsers) {
browsers[0].retrieveFileList(mDirectory, FileNode.Format.all, false) ;
return browsers[0] ;
}
@Override
protected void onPostExecute(FileBrowser result) {
Activity activity = getActivity() ;
if (activity == null)
return ;
if (activity != null) {
List<FileNode> fileList = result.getFileList() ;
mFileList.addAll(fileList) ;
mFileListAdapter.notifyDataSetChanged() ;
if (!result.isCompleted() && fileList.size() != 0) {
mFileListTitle.setText(mFileBrowser + " : " + mReading + " " + mDirectory + " ("
+ mFileList.size() + " " + mItems +")") ;
Log.i(TAG, "mFileListTitle-----11111 = " + mFileListTitle.getText());
new ContiunedDownloadTask().execute(result) ;
} else {
mFileListTitle.setText(mFileBrowser + " : " + mDirectory + " (" + mFileList.size()
+ " " + mItems +")") ;
Log.i(TAG, "mFileListTitle-----22222 = " + mFileListTitle.getText());
setWaitingState(false) ;
}
}
}
}
如何拨打另一个AsyncTask
FileBrowserFragment
中的fragment
?
答案 0 :(得分:2)
只需在自己的文件中创建asynctask即可。为此,请创建另一个名为ContiunedDownloadTask.java的Java文件,并在其中复制您的类。然后你可以调用下面的方法:
new ContiunedDownloadTask().execute(fileBrowser);
如果你真的想在class的类中保留类定义,那么你需要将它设置为public static并像这样调用它:
new FileBrowserFragment.ContiunedDownloadTask().execute(fileBrowser);