Recent

Author Topic: "setTextAsLink" does not work in "jTextView"  (Read 4159 times)

ADiV

  • Jr. Member
  • **
  • Posts: 62
    • ADiV Software
"setTextAsLink" does not work in "jTextView"
« on: August 14, 2018, 09:50:04 am »
"setTextAsLink" does not work in "jTextView". It produces a fatal error when executed in Android.

ADiV

  • Jr. Member
  • **
  • Posts: 62
    • ADiV Software
Re: "setTextAsLink" does not work in "jTextView"
« Reply #1 on: August 14, 2018, 05:01:53 pm »
I have changed the code for this one that works better, what you have to keep in mind both in this code and in the other that you should not call this function in the "AndroidModuleActivityCreate" since it gives an error in runtime. Attached full source code.

Code: Java  [Select][+][-]
  1. public void SetTextAsLink(String _linkText) {
  2.  
  3.                //[ifdef_api24up]
  4.                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N){
  5.                    this.setText(Html.fromHtml(_linkText, Html.FROM_HTML_MODE_LEGACY));
  6.                }else //[endif_api24up]
  7.                    this.setText(Html.fromHtml(_linkText));
  8.  
  9.                this.setMovementMethod(LinkMovementMethod.getInstance());
  10.         }
  11.  

jmpessoa

  • Hero Member
  • *****
  • Posts: 1507
Re: "setTextAsLink" does not work in "jTextView"
« Reply #2 on: August 14, 2018, 06:31:45 pm »
Quote
you should not call this function in the "AndroidModuleActivityCreate" since it gives an error in runtime...

Ok. You can try handle  "OnJNIPrompt" ...

I will commit your  fixed code.

Thank you!!!
« Last Edit: August 14, 2018, 06:56:07 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

ADiV

  • Jr. Member
  • **
  • Posts: 62
    • ADiV Software
Re: "setTextAsLink" does not work in "jTextView"
« Reply #3 on: August 16, 2018, 10:04:46 am »
@jmpessoa
New function for "jTextView", allows us to select the color of the link. I attach source code with the modifications.

Code: Java  [Select][+][-]
  1. public void SetTextAsLink(String _linkText, int _color) {
  2.  
  3.                //[ifdef_api24up]
  4.                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N){
  5.                    this.setText(Html.fromHtml(_linkText, Html.FROM_HTML_MODE_LEGACY));
  6.                }else //[endif_api24up]
  7.                    this.setText(Html.fromHtml(_linkText));
  8.  
  9.                this.setMovementMethod(LinkMovementMethod.getInstance());
  10.                this.setLinkTextColor(_color);
  11.         }

We would use it for example like this:
Code: Pascal  [Select][+][-]
  1. lbInfoCfg.SetTextAsLink('<a href=''http://www.google.com''>Go to Google</a>', GetARGB(0,colbrRed));
  2.  
« Last Edit: August 27, 2018, 04:09:57 pm by TR3E »

 

TinyPortal © 2005-2018