flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

Question: How to get the row/line for a view at certain position

Open omhack opened this issue 4 years ago • 2 comments

  • [x] I have searched existing issues and confirmed this is not a duplicate

How to get the row/line for a desired view

Is there a way to get a selected view's row/line number?, I want to know what line a view at certain position belongs to.

omhack avatar Dec 18 '20 13:12 omhack

It's a very good question. I was struggling with it when tried to create a proper ItemDecoration. Maybe someone knows convenient way of getting the line number, line length and the position in line?

I found package-private method that is used by FlexboxItemDecoration to find out the line number.

int getPositionOnFlexLineIndex(int position)

But it is package-private and can't be used from the outside.

ruslansharipov avatar Jan 13 '21 20:01 ruslansharipov

I found a (dirty) solution for this problem without modifying the classes of this repo manually: In your custom project, create a package with the same package name of FlexboxItemDecoratiom. Then create a new class in this package, for example "PackageProtectionCaller.java". In this class you can define static public methods and can access the package protected methods and variables.

Not a smooth solution, but sometimes the only way to handle data.

0-99 avatar Sep 25 '21 00:09 0-99