Hypertext: Java Source Code


Next Page



Home Page

MyApplication/app/src/main/java/com/example/wenchen/myapplication/MainActivity.java
package com.example.wenchen.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.URLSpan;

public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_main );
    TextView tv = (TextView) findViewById( R.id.txtMsg );
    MainActivity.makeTextViewHyperlink( tv );
    tv.setOnClickListener( new View.OnClickListener( ) {
      @Override
      public void onClick( View v ) {
        Intent intent = new Intent( MainActivity.this, NextActivity.class );
        startActivity( intent );
      }
    } );
  }

  // Sets a hyperlink style to the textview.
  public static void makeTextViewHyperlink( TextView tv ) {
    SpannableStringBuilder ssb = new SpannableStringBuilder( );
    ssb.append( tv.getText( ) );
    ssb.setSpan( new URLSpan("#"), 0, ssb.length(),
      Spanned.SPAN_EXCLUSIVE_EXCLUSIVE );
    tv.setText( ssb, TextView.BufferType.SPANNABLE );
  }
}




      Do you not see how necessary a world of pains and troubles    
      is to school an intelligence and make it a soul?    
      ― John Keats, Letters of John Keats