In order to convert string to html format, we can use htmlEncode() method of TextUtils class.
 
package com.exercise.AndroidHtmlEncode;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
public class AndroidHtmlEncodeActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TextView textSrc = (TextView)findViewById(R.id.src);
        TextView textDest = (TextView)findViewById(R.id.dest);
        
        String src = "example: <activity>";
        String dest = TextUtils.htmlEncode(src);
        
        textSrc.setText(src);
        textDest.setText(dest);
    }
}
No comments:
Post a Comment