linkedin / Spyglass

A library for mentions on Android
Apache License 2.0
387 stars 128 forks source link

How do I get the starting and ending index of a mention username in a piece of a string ? #135

Closed kartikterralogic closed 6 months ago

kartikterralogic commented 6 months ago

For example.

Hello world @sheeja , hello @akshay.

Now how can i get start index value and end index value of sheeja and akshay ?

sheeja --> start index is : 14 end index is : 20

akshay --> start index : 30 end index : 35.

nhibner commented 6 months ago

You can just invoke the getSpans(..) function. It would look something like:

// This will return two spans, one for sheeja, another for akshay
val spans: Array<MentionSpan> = text.getSpans(0, text.length)

Please note that this library only supports using Android views and is not intended/designed to work with Compose (primarily since this library was mostly written ~9 years ago).

Closing this issue since it's just a general Android coding question, not really an issue related to the library. Hopefully the above help!

kartikterralogic commented 6 months ago

This is I know: does the specified span return the values for the start and end index? By programming we can able to get the index values, Do we have specified within library itself ?

nhibner commented 6 months ago

There are methods to get the start and end of a span, see the methods in this interface.