
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<EditText
    android:id="@+id/editfield"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    />
</LinearLayout>
AndroidLinkify.java
package com.exercise.AndroidLinkify;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
public class AndroidLinkify extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final EditText editField = (EditText)findViewById(R.id.editfield);
        editField.setOnKeyListener(new EditText.OnKeyListener(){
   @Override
   public boolean onKey(View v, int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    Linkify.addLinks(editField, 
      Linkify.EMAIL_ADDRESSES|
      Linkify.MAP_ADDRESSES|
      Linkify.PHONE_NUMBERS|
      Linkify.WEB_URLS);
    return false;
   }});
    }
}
No comments:
Post a Comment