I am attempting to contain a WebView within a PopupWindow. The WebView is to display Wikipedia pages.
Interestingly, the WebView works as I intend when using the simulator. When I use the app on my test device (an original ASUS Transformer), instead of the Web Page displaying within the Popup, the popup comes up, my loader shows loading progress, but then the default web browser comes up to display the web page. Again, it works as intended in the simulator where the page displays within the Popup window. I have looked at many sites, including many many posts here on SO, and nothing I have tried works. I am hoping someone else has seen this in one of their app developments.
The code I have implemented for a setup of the button, PopupWindow, and WebView is:
WikiButton = (ImageButton)findViewById(R.id.WikiButton);
htmlProgress = (ProgressBar)elemWebView.findViewById(R.id.htmlProgressBar);
htmlShowing = -1;
// Necessary for the Info Popup window
infoWebViewPopup = new PopupWindow(infoWebView = inflater.inflate(R.layout.property_info_layout, null, false), 1105, 685, true);
infoWebViewPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
infoWebViewPopup.setFocusable(false);
infoWebHTMLView = (WebView)infoWebView.findViewById(R.id.infoWebHTMLView);
WebSettings mySettingsInfo = elemWebHTMLView.getSettings();
mySettingsInfo.setJavaScriptEnabled(true);
The Button Action Code is:
WikiButton.setOnClickListener(new View.OnClickListener(){
infoWebHTMLView.clearView();
String urlToGet = "http://en.wikipedia.org/wiki/" + "SOME OTHER STRING HERE";
// Load the URL into the web view
infoWebHTMLView.loadUrl(urlToGet);
// Calculate posX and posY for placement
infoWebViewPopup.setOutsideTouchable(false);
infoWebViewPopup.showAtLocation(findViewById(R.id.properties_view), Gravity.LEFT | Gravity.TOP, posX, posY);
}
Other code I have implemented for the WebView:
infoWebHTMLView.setWebChromeClient(new WebChromeClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
public void onProgressChanged(WebView view, int progress) {
elemWebHTMLView.invalidate();
htmlProgress.setProgress(progress);
if(progress >= 100){
htmlProgress.setVisibility(View.INVISIBLE);
}else{
htmlProgress.setVisibility(View.VISIBLE);
}
}
});
The PopupWindow, WebView, and Button have all been defined in XML files.
ANY help would be appreciated, and thanks much.
You should be using WebViewClient, not WebChromeClient.
Make sure to add @Override annotations when you’re overriding methods. You’ll get an error if you thought you were overriding a method but it actually doesn’t exist.