Devin
Devin

Reputation: 131

Text viewed as HTML

Hey everyone this is a update from my previous question https://stackoverflow.com/questions/6676440/android-showing-a-edittext-text-in-webview

I got the webview to see the text inside my Edit text field but its displaying it as text this is the coding im using

    case R.id.Preview:
        Intent j = new Intent(this, Preview.class);
        j.putExtra(com.afajje.htmlzero.Preview.URL, 
                myEditText.getText().toString());
        startActivity(j);
}
return false;} 

Want im trying to have it do is view the Edit text, text as HTML

For example if I put in the Edittext field

<html>
<head>
</head>
<body>
<p>This is a Preview</p>
</body>
</html>

In the web view itll just just the "This is a Preview"

Upvotes: 0

Views: 815

Answers (3)

Turnsole
Turnsole

Reputation: 3472

Here ya go, a working demo:

package com.stackexchange.test;

import android.app.Activity; 
import android.os.Bundle; 
import android.text.Html; 
import android.text.Spanned; 
import android.widget.EditText;

public class home extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        EditText box = (EditText) findViewById(R.id.edittext);
        String htmltext = "<b>This is bold. </ b> and <i> this is italic </ i>." ; 
        Spanned text = Html.fromHtml( htmltext ); 
        box.setText( text );
    } 
}

You should see (except that I've edited the text in the app):

enter image description here

Upvotes: 2

Finuka
Finuka

Reputation: 730

Well, in the editText, if you dont use "Html.fromHtml", the string will be display with the html tags. In a WebView, I really dont know what zou want to do...sorry

Upvotes: 0

Chirag
Chirag

Reputation: 56925

Try the below code to show the html text into the EditText.

 String str = "<html><head></head><body><p>This is a Preview</p></body></html>";
 editText = (EditText)findViewById(R.id.editText);
 editText.setText(Html.fromHtml(str));

enter image description here

Upvotes: 0

Related Questions