URLSpan onclick

Put your problem here if it does not fit any of the other categories.

URLSpan onclick

Postby doddi » Wed Nov 26, 2008 3:07 pm

Hi,

Forgive me if you have seen this posted elsewhere but I am struggling to get a response.
I am new to java and developing on android so am trying out a few little ideas.

I am trying to make some text in a TextView or EditText be clickable just like a hyperlink. There doesnt seem to be too much available on the web but here is what I have so far.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.            public void onCreate(Bundle savedInstanceState) {
  3.  
  4.                 super.onCreate(savedInstanceState);
  5.  
  6.                 setContentView(R.layout.main);
  7.  
  8.  
  9.  
  10.                 final EditText tv = (EditText)findViewById(R.id.txtView);    
  11.  
  12.                 //tv.setOnClickListener(txtClicked);
  13.  
  14.  
  15.  
  16.                 Spannable span = (Spannable) tv.getText();
  17.  
  18.                 URLSpan url = new URLSpan("www.google.co.uk") {
  19.  
  20.  
  21.  
  22.                     /* (non-Javadoc)
  23.  
  24.                      * @see com.loosenoose.hyperlinktext.myURLSpan#onClick(android.view.View)
  25.  
  26.                      */
  27.  
  28.                     @Override
  29.  
  30.                     public void onClick(View widget) {
  31.  
  32.                         // TODO Auto-generated method stub
  33.  
  34.                         tv.setText("URL Clicked!");
  35.  
  36.                        
  37.  
  38.                         super.onClick(widget);          
  39.  
  40.                     }
  41.  
  42.                    
  43.  
  44.                 };
  45.  
  46.                 span.setSpan(url, 0, 5, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  47.  
  48.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


My problem is that the onClick event never seems to be called when debugging. Can someone please help?

cheers
doddi
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Nov 26, 2008 3:01 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests