3

I am trying a lot but it is not wroking. Here's my code:

public class SchofferStr extends Activity {

    String summary = "<html><body>You scored <b>192</b> points.</body></html>";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        WebView webview = new WebView(this);
        setContentView(webview);
        webview.loadData(summary, "text/html", "utf-8");
    }

}

the summary string i have is a lengthy htmlformatted table. But problem is this code is not even working for this simple html formated string. What is it that im doing wrong? Please help, im stuck.

2
  • 1
    First of all, you can't have setContentView called twice like that... Commented Nov 21, 2010 at 22:40
  • 2
    @Sephy: Of course you can. You can have as many setContentView() methods as you wish as the last one will simply override all the preceding ones. Commented Nov 21, 2010 at 22:50

1 Answer 1

9

Try:

webview.loadDataWithBaseURL(null, summary, "text/html", "UTF-8", null);
Sign up to request clarification or add additional context in comments.

3 Comments

Hi CommonsWare, I used loadDataWithBaseURL but still getting a blank output. The window appears but is totally blank as before. It is not showing anything. In my xml layout, i have also webview tag, if that has to do anything. What could be the reason. Is there anything else i should check??
@Rizwan: Start with this project: github.com/commonsguy/cw-android/tree/master/WebKit/Browser2 -- it is known to work. Then, adjust as needed.
Thankyou so much CommonsWare. I found my issue going through the example you referred me. I had to modify the AndroidManifest.xml file and add these lines to intent filter in my activity: "android.intent.action.MAIN" & "android.intent.category.LAUNCHER". It is working now. Thanks again, you solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.