Jumat, 14 Februari 2014

Html-encode string using TextUtils.htmlEncode()

TextUtils.htmlEncode(String s) Html-encode the string.

TextUtils.htmlEncode()
TextUtils.htmlEncode()

package com.example.androidtextutils;

import android.os.Bundle;
import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

EditText textSrc;
TextView textDest;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textSrc = (EditText)findViewById(R.id.textsrc);
textDest = (TextView)findViewById(R.id.textdest);
Button buttonConvert = (Button)findViewById(R.id.convert);
buttonConvert.setOnClickListener(buttonConvertOnClickListener);
}

View.OnClickListener buttonConvertOnClickListener =
new View.OnClickListener(){

@Override
public void onClick(View arg0) {
String src = (String) textSrc.getText().toString();
String dest = TextUtils.htmlEncode(src);
textDest.setText(dest);
}};


}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android-coding.blogspot.com" />

<EditText
android:id="@+id/textsrc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/convert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Html-encode the string" />
<TextView
android:id="@+id/textdest"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>


More example of using android.text.TextUtils and android.text.Html

0 komentar:

Posting Komentar

Copyright © 2012 Codding News All Right Reserved