0

Whenever I am using autoLink="all" in TextView, it is not properly autolinking the Mobile Number. It is autolinking the earlier Number(number from a text not mobile Number) as well.

Here is the layout

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:autoLink="all"
    android:textIsSelectable="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

The output is attached below

Issue Image

How to avoid that issue ?

Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55

1 Answers1

0

If I have understood your question clearly than you can also use ClickableSpan It also allows you to under line and clickable the fix number of characters handle the click for the same. In xml

<TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_18sdp"
                android:layout_marginRight="@dimen/_18sdp"
                android:fontFamily="@font/lato_semibold"
                android:paddingTop="@dimen/_15sdp"
                android:textAlignment="center"
                android:textColor="@color/colorBlack"
                android:textSize="@dimen/_13sdp" />

In java class

    SpannableString ss = new SpannableString("Hello World8 123456789");
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        // handle on click
    }
    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);

    }
};
ss.setSpan(clickableSpan, 12, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.hello);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);
Rozina
  • 409
  • 3
  • 14