Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:12:44+00:00 2026-06-09T13:12:44+00:00

I have a TextView with many ClickableSpan . On click on a ClickableSpan ,

  • 0

I have a TextView with many ClickableSpan.

On click on a ClickableSpan, I have to get the coordinate on screen of it (to show a custom View at his position).

The problem is that I have no idea of how I can do this. The onClick() method of the ClickableSpan gives me in parameter a View, the TextView which contains the ClickableSpan.

I have used the following to get characters position in the TextView, but I don’t know how I can convert it to get x/y position on screen of the text.

@Override
public void onClick(View v){

    SpannableString completeText = (SpannableString)((TextView) v).getText();
    Log.v("characters position", completeText.getSpanStart(this) + " / " + completeText.getSpanEnd(this));

}

Thanks in advance for your help!

EDIT : I want to get the entire coordinate of the ClickableSpan and its size, the aim is to show my custom view at the bottom center of the text. The onTouch method will give me the finger position, not the entire text coordinates. So, with this method, I will not have the middle of the text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:12:45+00:00Added an answer on June 9, 2026 at 1:12 pm

    I have found a solution 🙂
    Here it is, may be this will help others with the same problem like me !

    // Initialize global value
    this.parentTextViewRect = new Rect();
            
            
    // Initialize values for the computing of clickedText position
    SpannableString completeText = (SpannableString)(parentTextView).getText();
    Layout textViewLayout = parentTextView.getLayout();
            
    double startOffsetOfClickedText = completeText.getSpanStart(clickedText);
    double endOffsetOfClickedText = completeText.getSpanEnd(clickedText);
    double startXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal((int)startOffsetOfClickedText);
    double endXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal((int)endOffsetOfClickedText);
            
            
    // Get the rectangle of the clicked text
    int currentLineStartOffset = textViewLayout.getLineForOffset((int)startOffsetOfClickedText);
    int currentLineEndOffset = textViewLayout.getLineForOffset((int)endOffsetOfClickedText);
    boolean keywordIsInMultiLine = currentLineStartOffset != currentLineEndOffset;
    textViewLayout.getLineBounds(currentLineStartOffset, this.parentTextViewRect);
            
            
    // Update the rectangle position to his real position on screen
    int[] parentTextViewLocation = {0,0};
    parentTextView.getLocationOnScreen(parentTextViewLocation);
            
    double parentTextViewTopAndBottomOffset = (
        parentTextViewLocation[1] - 
        parentTextView.getScrollY() + 
        this.parentTextView.getCompoundPaddingTop()
    );
    this.parentTextViewRect.top += parentTextViewTopAndBottomOffset;
    this.parentTextViewRect.bottom += parentTextViewTopAndBottomOffset;
            
    // In the case of multi line text, we have to choose what rectangle take
    if (keywordIsInMultiLine){
                
        int screenHeight = this.mWindowManager.getDefaultDisplay().getHeight();
        int dyTop = this.parentTextViewRect.top;
        int dyBottom = screenHeight - this.parentTextViewRect.bottom;
        boolean onTop = dyTop > dyBottom;
                
        if (onTop){
            endXCoordinatesOfClickedText = textViewLayout.getLineRight(currentLineStartOffset);
        }
        else{
            this.parentTextViewRect = new Rect();
            textViewLayout.getLineBounds(currentLineEndOffset, this.parentTextViewRect);
            this.parentTextViewRect.top += parentTextViewTopAndBottomOffset;
            this.parentTextViewRect.bottom += parentTextViewTopAndBottomOffset;
            startXCoordinatesOfClickedText = textViewLayout.getLineLeft(currentLineEndOffset);
        }
                
    }
            
    this.parentTextViewRect.left += (
        parentTextViewLocation[0] +
        startXCoordinatesOfClickedText + 
        this.parentTextView.getCompoundPaddingLeft() - 
        parentTextView.getScrollX()
    );
    this.parentTextViewRect.right = (int) (
        this.parentTextViewRect.left + 
        endXCoordinatesOfClickedText - 
        startXCoordinatesOfClickedText
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have many views (textview) in linearlayout i want each view id when i
I have a full-screen TextView holding a long Spanned that requires scrolling. The TextView's
I have a TextView that displays an error message in the login page of
I want to have a TextView on the left that fills space, plus a
Guess that I have a TextView that I want to update it in some
Let's say you have a TextView that displays an number like 0 and you
I have a very strange problem with Android animations, I tried many different approaches
I have an app that tells me how many hours to go at school
I have an android activity that consists of a List View and a Text
i have a scrollview ,it include one textView, the textView have many lines,in other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.