gpt4 book ai didi

android - 将 AsyncTask onPreExecute 添加到 fragment

转载 作者:行者123 更新时间:2023-11-29 14:52:46 25 4
gpt4 key购买 nike

我想将 onPreExecute AsyncTask 添加到 SherlockFragment,但它会导致错误。我的代码如下。在 preExecute AsyncTask 上添加对话框的这段代码有什么问题?

public class customlist extends SherlockFragment  {
static final String URL = "esample";
static final String KEY_SONG = "song"; // parent node
private static final String KEY_TAB_NUM = "key.tab.num";
private ProgressDialog pDialog;


ListView list;
LazyAdapterbeth adapter;
XMLParser parser = new XMLParser();
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

}


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new getFeed().execute();

}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)

{
View thisfragment = inflater.inflate(R.layout.dovomi, container, false);

return thisfragment;
}




private class getFeed extends AsyncTask<Void, Void, Document> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(customlist.this);
pDialog.setTitle("Connect to Server");
pDialog.setMessage("This process can take a few seconds to a few minutes, depending on your Internet Connection Speed.");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}

protected Document doInBackground(Void... params) {

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element

return doc;
}

导致行中出现错误

pDialog = new ProgressDialog(customlist.this);

如何在此 fragment 中添加对话框或进度条?

最佳答案

ProgressDialog 将 Context 作为参数。由于您在 Fragment 中使用它,因此您可以改用 getActivity()

关于android - 将 AsyncTask onPreExecute 添加到 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13368592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com