我在尝试关闭(); 进度条对话框时,在完成进程时使用webview中的方法 onPostExecute 进行加载。 我的问题是当我在AsynTask中运行onPostExecute方法时从未执行过吗?
注意:我已阅读
public class MainActivity extends AppCompatActivity {
WebView webView;
EditText edInput;
Button btnCari;
String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
edInput = (EditText) findViewById(R.id.editText);
btnCari = (Button) findViewById(R.id.button);
btnCari.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
asynCaller myTask = new asynCaller();
myTask.execute();
}
});
}
private void loadWeb(String url){
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://"+url);
}
public class asynCaller extends AsyncTask<String, Void, String> {
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
url = edInput.getText().toString();
progressDialog.show(MainActivity.this,"Pesan","Memuat . . .",true);
}
@Override
protected String doInBackground(String... params) {
publishProgress();
return url;
}
@Override
protected void onPostExecute(String result) {
progressDialog.dismiss();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
loadWeb(url);
}
}
}