Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Linkify function in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 143
    Comment on it

    Using below code i have created Linkify function. Here I have created MainActivity class and In main.xml layout I have added Text View property. Below code will clearly described you how to make Linkify function.

    Step(1)-Create MainActivity-

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            TextView WebSiteone = (TextView) findViewById(R.id.textview1);
            WebSiteone.setText("Go to : google.com");
            Linkify.addLinks(WebSiteone, Linkify.WEB_URLS);
    
            TextView WebSitetwo = (TextView) findViewById(R.id.textview2);
            WebSitetwo.setText("Go to : Findnerd.com");
            Linkify.addLinks(WebSitetwo, Linkify.WEB_URLS);
    
            TextView myCustomLink = (TextView) findViewById(R.id.textView3);
            Pattern p1 = Pattern.compile("\\bAndroid+\\b");
            myCustomLink.setText("Click on Android " + 
            "to search it on google");
            Linkify.addLinks(myCustomLink, p1, "http://www.google.ie/search?q=");
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }
    

    Step(2)-AndoridManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.linkify"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.INTERNET"/>
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.linkify.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    

    Step(3)-Main.xml layout

    <RelativeLayout 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"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/textview1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="95dp"
            android:text="hello"
            android:textSize="30dp" />
    
        <TextView
            android:id="@+id/textview2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="186dp"
            android:text="sanfoundry"
            android:textSize="30dp" />
    
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textview2"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/textview2"
            android:layout_marginTop="88dp"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: