Issue
I am trying to open an url in a new webview (created in a non activity class).
When debugging the mContext
is not null, and i am on the main thread. I can see the toast and the last print but the webview is not shown. I don't understand what i am doing wrong.. can you spot a mistake? Thank you
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, "test", Toast.LENGTH_LONG).show();
System.out.println("creating a new webview");
WebView wv = new WebView(mContext);
wv.loadUrl("urlhere");
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
System.out.println("finished loading url: " + url);
}
public void onLoadResource(WebView view, String url) {
}
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
return true;
}
});
wv.setVisibility(View.VISIBLE);
System.out.println("should see the webview now");
}
});
Solution
You are creating a new WebView but not giving it a parent where it can attach and display. Or use it in a setContentView.
Answered By - greenapps
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.