Aplicație Android Webview cu ProgressDialog
Ultima postare: feb 23 2012 00:39, Inițiat de
sebyku17
, feb 23 2012 00:39
·
0
#1
Publicat: 23 februarie 2012 - 00:39
Încerc să fac o aplicație webview dar numai cum vreau eu nu îmi iese. Ideea e sa îmi apara acel progress Dialog de fiecare dată când se încarcă o pagină, unele pagini sunt cu iframe-uri de exemplu paginile cu facebook like, comment plugin șamd. Eu voi posta codul ce am reușit să fac și poate mă ajută cineva să îi dau de cap.
private WebView webview; private ProgressDialog progressDialog; boolean loadingFinished = true; boolean redirect = false; int nr = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webview = (WebView) findViewById(R.string.webview); final Activity activity = this; webview.getSettings().setJavascriptEnabled(true); webview.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!loadingFinished) { redirect = true; } loadingFinished = false; webview.loadUrl(url); return true; } public void onloadResource(WebView view, String url) { if (progressDialog == null) { progressDialog = new ProgressDialog(activity); progressDialog.setTitle("PitziWorld"); progressDialog.setMessage(progressDialog.toString()); progressDialog.setCancelable(isFinishing()); progressDialog.show(); } loadingFinished = false; } public void onPageFinished(WebView view, String url) { if(!redirect){ loadingFinished = true; } if(loadingFinished && !redirect){ if (progressDialog.isShowing() || progressDialog!=null) { progressDialog.hide(); progressDialog = null; } } else{ redirect = false; } } }); webview.loadUrl("http://www.example.com"); } @Override public boolean onkeydown(int keyCode, KeyEvent event) { WebView webView = (WebView) findViewById(R.string.webview); //Verifica daca tasta apasata a fost back si daca exista istoric if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { webView.goBack(); return true; } // Daca nu a fost tasta back sau nu este istoric, returnam valoare buton |
Anunturi
Bun venit pe Forumul Softpedia!
▶ Utilizatori activi: 1
0 membri, 1 vizitatori, 0 utilizatori anonimi