Reputation: 1644
I am trying to show a html file from assets folder into a Custom Dialog Box. But getting Errors. I am using following Codes.
My Custom Dialog Class
public class RobozoxDialog extends Activity{
Dialog my;
public RobozoxDialog(Context theContext){
my= new Dialog(theContext);
}
public void showRobozoxDialog(){
my.show();
}
public void setSource(String title,String url) {
WebView myWebView = (WebView) findViewById(R.id.webview_dialog);
myWebView.loadUrl(url);
my.setTitle(title);
}
}
Custom Dialog XML
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</WebView>
Calling Dialog Like this.
RobozoxDialog d = new RobozoxDialog(MainActivity.this);
d.setSource("Test", "file:///android_asset/test.html");
d.showRobozoxDialog();
But getting error and unable to solve the problem. When i show html file in webview of main activity xml it is showing. but when try to show in dialog webview it stops working..
Upvotes: 0
Views: 827
Reputation: 1644
I done this by using LayoutInflater Code is below..
LayoutInflater li = LayoutInflater.from(theContext);
View promptsView = li.inflate(R.layout.dialog_layout, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
theContext);
alertDialogBuilder.setTitle("Registration");
alertDialogBuilder.setView(promptsView);
final WebView webview = (WebView) promptsView
.findViewById(R.id.webview_dialog);
webview.loadUrl("file:///android_asset/test.html");
final AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
Upvotes: 1
Reputation: 10977
my.findViewById(R.id.webview_dialog)
Upvotes: 0