我想将 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);
如何在此片段中添加对话框或进度条?