Android autolinks: Skip numbers having less than 10 digits












-1














I have a textview with autoLinks set to all. I want Skip numbers like "2018"
which are years, these numbers should not be highlighted. Is there a delimiter i can use in the text so that it skips
those numbers while parsing?










share|improve this question
























  • this question may help you [stackoverflow.com/questions/10246366/…
    – nariman amani
    Nov 20 at 5:21










  • No, i wanted a delimiter kind of thing that would skip that particular word or in my case a number.
    – rohiththammaiah
    Nov 21 at 5:19
















-1














I have a textview with autoLinks set to all. I want Skip numbers like "2018"
which are years, these numbers should not be highlighted. Is there a delimiter i can use in the text so that it skips
those numbers while parsing?










share|improve this question
























  • this question may help you [stackoverflow.com/questions/10246366/…
    – nariman amani
    Nov 20 at 5:21










  • No, i wanted a delimiter kind of thing that would skip that particular word or in my case a number.
    – rohiththammaiah
    Nov 21 at 5:19














-1












-1








-1







I have a textview with autoLinks set to all. I want Skip numbers like "2018"
which are years, these numbers should not be highlighted. Is there a delimiter i can use in the text so that it skips
those numbers while parsing?










share|improve this question















I have a textview with autoLinks set to all. I want Skip numbers like "2018"
which are years, these numbers should not be highlighted. Is there a delimiter i can use in the text so that it skips
those numbers while parsing?







android android-layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 5:11

























asked Nov 20 at 5:02









rohiththammaiah

1324




1324












  • this question may help you [stackoverflow.com/questions/10246366/…
    – nariman amani
    Nov 20 at 5:21










  • No, i wanted a delimiter kind of thing that would skip that particular word or in my case a number.
    – rohiththammaiah
    Nov 21 at 5:19


















  • this question may help you [stackoverflow.com/questions/10246366/…
    – nariman amani
    Nov 20 at 5:21










  • No, i wanted a delimiter kind of thing that would skip that particular word or in my case a number.
    – rohiththammaiah
    Nov 21 at 5:19
















this question may help you [stackoverflow.com/questions/10246366/…
– nariman amani
Nov 20 at 5:21




this question may help you [stackoverflow.com/questions/10246366/…
– nariman amani
Nov 20 at 5:21












No, i wanted a delimiter kind of thing that would skip that particular word or in my case a number.
– rohiththammaiah
Nov 21 at 5:19




No, i wanted a delimiter kind of thing that would skip that particular word or in my case a number.
– rohiththammaiah
Nov 21 at 5:19












4 Answers
4






active

oldest

votes


















0














try this....



String s1="jan 2018,Saturday";  
String replaceString=s1.replace("2018","");//replaces all occurrences of "2018" to ""
System.out.println(replaceString);



Output := jan ,Saturday.







share|improve this answer























  • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
    – rohiththammaiah
    Nov 20 at 5:17










  • have to tried anythings ?
    – Sushil Kumar
    Nov 20 at 5:19



















0














Use Spanable String in this case to highlight Specific String.



Here is an example:
SpannableString spannableStr = new SpannableString(originalText);
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
spannableStr.setSpan(foregroundColorSpan, 15, 30, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
spannableTextView.setText(spannableStr);



Set color and starting string index and ending index.



For more detail check this link click this link






share|improve this answer





























    0














    I searched for your answer try this



    private void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
    int start = s.getSpanStart(span);
    int end = s.getSpanEnd(span);
    s.removeSpan(span);
    span = new URLSpanNoUnderline(span.getURL());
    s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
    }


    This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:



    private class URLSpanNoUnderline extends URLSpan {
    public URLSpanNoUnderline(String url) {
    super(url);
    }
    @Override public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setUnderlineText(false);
    }
    }


    here is the link






    share|improve this answer





























      0














      Try This Code :



      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      textView = findViewById(R.id.textView);
      highlightTv();

      }
      protected void highlightTv(){
      // Specify the text/word to highlight inside TextView
      String textToHighlight = "2018";

      // Construct the formatted text
      String replacedWith = "<font color='green'>" + textToHighlight + "</font>";

      // Get the text from TextView
      String originalString = textView.getText().toString();

      // Replace the specified text/word with formatted text/word
      String modifiedString = originalString.replaceAll(textToHighlight,replacedWith);

      // Update the TextView text
      mTextView.setText(Html.fromHtml(modifiedString));
      }





      share|improve this answer























      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
        – rohiththammaiah
        Nov 20 at 5:13










      • @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
        – Sniffer
        Nov 20 at 5:24











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386511%2fandroid-autolinks-skip-numbers-having-less-than-10-digits%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      try this....



      String s1="jan 2018,Saturday";  
      String replaceString=s1.replace("2018","");//replaces all occurrences of "2018" to ""
      System.out.println(replaceString);



      Output := jan ,Saturday.







      share|improve this answer























      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
        – rohiththammaiah
        Nov 20 at 5:17










      • have to tried anythings ?
        – Sushil Kumar
        Nov 20 at 5:19
















      0














      try this....



      String s1="jan 2018,Saturday";  
      String replaceString=s1.replace("2018","");//replaces all occurrences of "2018" to ""
      System.out.println(replaceString);



      Output := jan ,Saturday.







      share|improve this answer























      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
        – rohiththammaiah
        Nov 20 at 5:17










      • have to tried anythings ?
        – Sushil Kumar
        Nov 20 at 5:19














      0












      0








      0






      try this....



      String s1="jan 2018,Saturday";  
      String replaceString=s1.replace("2018","");//replaces all occurrences of "2018" to ""
      System.out.println(replaceString);



      Output := jan ,Saturday.







      share|improve this answer














      try this....



      String s1="jan 2018,Saturday";  
      String replaceString=s1.replace("2018","");//replaces all occurrences of "2018" to ""
      System.out.println(replaceString);



      Output := jan ,Saturday.








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 20 at 5:15

























      answered Nov 20 at 5:07









      Sushil Kumar

      4,84731656




      4,84731656












      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
        – rohiththammaiah
        Nov 20 at 5:17










      • have to tried anythings ?
        – Sushil Kumar
        Nov 20 at 5:19


















      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
        – rohiththammaiah
        Nov 20 at 5:17










      • have to tried anythings ?
        – Sushil Kumar
        Nov 20 at 5:19
















      I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
      – rohiththammaiah
      Nov 20 at 5:17




      I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
      – rohiththammaiah
      Nov 20 at 5:17












      have to tried anythings ?
      – Sushil Kumar
      Nov 20 at 5:19




      have to tried anythings ?
      – Sushil Kumar
      Nov 20 at 5:19













      0














      Use Spanable String in this case to highlight Specific String.



      Here is an example:
      SpannableString spannableStr = new SpannableString(originalText);
      ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
      spannableStr.setSpan(foregroundColorSpan, 15, 30, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
      spannableTextView.setText(spannableStr);



      Set color and starting string index and ending index.



      For more detail check this link click this link






      share|improve this answer


























        0














        Use Spanable String in this case to highlight Specific String.



        Here is an example:
        SpannableString spannableStr = new SpannableString(originalText);
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
        spannableStr.setSpan(foregroundColorSpan, 15, 30, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spannableTextView.setText(spannableStr);



        Set color and starting string index and ending index.



        For more detail check this link click this link






        share|improve this answer
























          0












          0








          0






          Use Spanable String in this case to highlight Specific String.



          Here is an example:
          SpannableString spannableStr = new SpannableString(originalText);
          ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
          spannableStr.setSpan(foregroundColorSpan, 15, 30, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
          spannableTextView.setText(spannableStr);



          Set color and starting string index and ending index.



          For more detail check this link click this link






          share|improve this answer












          Use Spanable String in this case to highlight Specific String.



          Here is an example:
          SpannableString spannableStr = new SpannableString(originalText);
          ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED);
          spannableStr.setSpan(foregroundColorSpan, 15, 30, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
          spannableTextView.setText(spannableStr);



          Set color and starting string index and ending index.



          For more detail check this link click this link







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 5:23









          Danish Hassan

          11




          11























              0














              I searched for your answer try this



              private void stripUnderlines(TextView textView) {
              Spannable s = new SpannableString(textView.getText());
              URLSpan spans = s.getSpans(0, s.length(), URLSpan.class);
              for (URLSpan span: spans) {
              int start = s.getSpanStart(span);
              int end = s.getSpanEnd(span);
              s.removeSpan(span);
              span = new URLSpanNoUnderline(span.getURL());
              s.setSpan(span, start, end, 0);
              }
              textView.setText(s);
              }


              This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:



              private class URLSpanNoUnderline extends URLSpan {
              public URLSpanNoUnderline(String url) {
              super(url);
              }
              @Override public void updateDrawState(TextPaint ds) {
              super.updateDrawState(ds);
              ds.setUnderlineText(false);
              }
              }


              here is the link






              share|improve this answer


























                0














                I searched for your answer try this



                private void stripUnderlines(TextView textView) {
                Spannable s = new SpannableString(textView.getText());
                URLSpan spans = s.getSpans(0, s.length(), URLSpan.class);
                for (URLSpan span: spans) {
                int start = s.getSpanStart(span);
                int end = s.getSpanEnd(span);
                s.removeSpan(span);
                span = new URLSpanNoUnderline(span.getURL());
                s.setSpan(span, start, end, 0);
                }
                textView.setText(s);
                }


                This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:



                private class URLSpanNoUnderline extends URLSpan {
                public URLSpanNoUnderline(String url) {
                super(url);
                }
                @Override public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setUnderlineText(false);
                }
                }


                here is the link






                share|improve this answer
























                  0












                  0








                  0






                  I searched for your answer try this



                  private void stripUnderlines(TextView textView) {
                  Spannable s = new SpannableString(textView.getText());
                  URLSpan spans = s.getSpans(0, s.length(), URLSpan.class);
                  for (URLSpan span: spans) {
                  int start = s.getSpanStart(span);
                  int end = s.getSpanEnd(span);
                  s.removeSpan(span);
                  span = new URLSpanNoUnderline(span.getURL());
                  s.setSpan(span, start, end, 0);
                  }
                  textView.setText(s);
                  }


                  This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:



                  private class URLSpanNoUnderline extends URLSpan {
                  public URLSpanNoUnderline(String url) {
                  super(url);
                  }
                  @Override public void updateDrawState(TextPaint ds) {
                  super.updateDrawState(ds);
                  ds.setUnderlineText(false);
                  }
                  }


                  here is the link






                  share|improve this answer












                  I searched for your answer try this



                  private void stripUnderlines(TextView textView) {
                  Spannable s = new SpannableString(textView.getText());
                  URLSpan spans = s.getSpans(0, s.length(), URLSpan.class);
                  for (URLSpan span: spans) {
                  int start = s.getSpanStart(span);
                  int end = s.getSpanEnd(span);
                  s.removeSpan(span);
                  span = new URLSpanNoUnderline(span.getURL());
                  s.setSpan(span, start, end, 0);
                  }
                  textView.setText(s);
                  }


                  This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:



                  private class URLSpanNoUnderline extends URLSpan {
                  public URLSpanNoUnderline(String url) {
                  super(url);
                  }
                  @Override public void updateDrawState(TextPaint ds) {
                  super.updateDrawState(ds);
                  ds.setUnderlineText(false);
                  }
                  }


                  here is the link







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 5:25









                  Kevin Kurien

                  480110




                  480110























                      0














                      Try This Code :



                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_main);

                      textView = findViewById(R.id.textView);
                      highlightTv();

                      }
                      protected void highlightTv(){
                      // Specify the text/word to highlight inside TextView
                      String textToHighlight = "2018";

                      // Construct the formatted text
                      String replacedWith = "<font color='green'>" + textToHighlight + "</font>";

                      // Get the text from TextView
                      String originalString = textView.getText().toString();

                      // Replace the specified text/word with formatted text/word
                      String modifiedString = originalString.replaceAll(textToHighlight,replacedWith);

                      // Update the TextView text
                      mTextView.setText(Html.fromHtml(modifiedString));
                      }





                      share|improve this answer























                      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
                        – rohiththammaiah
                        Nov 20 at 5:13










                      • @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
                        – Sniffer
                        Nov 20 at 5:24
















                      0














                      Try This Code :



                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_main);

                      textView = findViewById(R.id.textView);
                      highlightTv();

                      }
                      protected void highlightTv(){
                      // Specify the text/word to highlight inside TextView
                      String textToHighlight = "2018";

                      // Construct the formatted text
                      String replacedWith = "<font color='green'>" + textToHighlight + "</font>";

                      // Get the text from TextView
                      String originalString = textView.getText().toString();

                      // Replace the specified text/word with formatted text/word
                      String modifiedString = originalString.replaceAll(textToHighlight,replacedWith);

                      // Update the TextView text
                      mTextView.setText(Html.fromHtml(modifiedString));
                      }





                      share|improve this answer























                      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
                        – rohiththammaiah
                        Nov 20 at 5:13










                      • @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
                        – Sniffer
                        Nov 20 at 5:24














                      0












                      0








                      0






                      Try This Code :



                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_main);

                      textView = findViewById(R.id.textView);
                      highlightTv();

                      }
                      protected void highlightTv(){
                      // Specify the text/word to highlight inside TextView
                      String textToHighlight = "2018";

                      // Construct the formatted text
                      String replacedWith = "<font color='green'>" + textToHighlight + "</font>";

                      // Get the text from TextView
                      String originalString = textView.getText().toString();

                      // Replace the specified text/word with formatted text/word
                      String modifiedString = originalString.replaceAll(textToHighlight,replacedWith);

                      // Update the TextView text
                      mTextView.setText(Html.fromHtml(modifiedString));
                      }





                      share|improve this answer














                      Try This Code :



                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_main);

                      textView = findViewById(R.id.textView);
                      highlightTv();

                      }
                      protected void highlightTv(){
                      // Specify the text/word to highlight inside TextView
                      String textToHighlight = "2018";

                      // Construct the formatted text
                      String replacedWith = "<font color='green'>" + textToHighlight + "</font>";

                      // Get the text from TextView
                      String originalString = textView.getText().toString();

                      // Replace the specified text/word with formatted text/word
                      String modifiedString = originalString.replaceAll(textToHighlight,replacedWith);

                      // Update the TextView text
                      mTextView.setText(Html.fromHtml(modifiedString));
                      }






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 20 at 5:52

























                      answered Nov 20 at 5:10









                      Sniffer

                      6371722




                      6371722












                      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
                        – rohiththammaiah
                        Nov 20 at 5:13










                      • @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
                        – Sniffer
                        Nov 20 at 5:24


















                      • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
                        – rohiththammaiah
                        Nov 20 at 5:13










                      • @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
                        – Sniffer
                        Nov 20 at 5:24
















                      I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
                      – rohiththammaiah
                      Nov 20 at 5:13




                      I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text
                      – rohiththammaiah
                      Nov 20 at 5:13












                      @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
                      – Sniffer
                      Nov 20 at 5:24




                      @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot
                      – Sniffer
                      Nov 20 at 5:24


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386511%2fandroid-autolinks-skip-numbers-having-less-than-10-digits%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      Origin of the phrase “under your belt”?