我想要一个Progressbar显示文件正在加载,如果没有互联网连接,一个简单的对话框应该显示。我知道如何使用WebView来实现它?
public class RetrievePDFStream extends AsyncTask<String,Void,InputStream>{
@Override
protected InputStream doInBackground(String... strings) {
InputStream inputStream = null;
try
{
URL url = new URL(strings[0]);
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
if (urlConnection.getResponseCode() == 200)
{
inputStream = new BufferedInputStream(urlConnection.getInputStream());
}
}
catch (IOException e)
{
return null;
}
return inputStream;
}
class MyTask extends AsyncTask<Integer, Integer, String> {
@Override
protected String doInBackground(Integer... params) {
for (; count <= params[0]; count++) {
try {
Thread.sleep(1000);
publishProgress(count);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "Task Completed.";
}
}
@Override
protected void onPostExecute(InputStream inputStream) {
progressBar.setVisibility(View.GONE);
pdfView.fromStream(inputStream).load();
}
}
发布于 2018-07-30 15:12:44
就像这样:
private ProgressDialog pd; //declare it
pd = new ProgressDialog(this); //instantiate it
然后你可以设置它的信息和标题.。
pd.setTitle(""); //set title
pd.setMessage(""); //set message
pd.setCanceledOnTouchOutside(false); //user cannot close progress dialog box
当你的任务开始时,将显示“进度”对话框。
pd.show();
当你的任务完成后:
pd.dismiss();
https://stackoverflow.com/questions/-100005862
复制相似问题