I have inflated a View into a PopupWindow. This View includes a TextView where I want to place text at runtime. I need to count the number of lines the TextView uses in order to adjust the size of the pop-up. For this purpose I use TextView's getLineCount() and draw the TextView before counting the number of lines ( myTextView.draw(canvas) ).
However, the first time I call the PopupWindow the getLineCount() returns the number of characters and not the number of lines (e.g 42 instead of 2) Debug prits suggest this is because the TextView is not properly initiated:
DEBUG/View(207): frame={0, 0, 0, 0} scroll={0, 0} DEBUG/View(207): mMeasureWidth=0 mMeasureHeight=0 DEBUG/View(207): privateFlags={} DEBUG/View(207): frame={0, 0, 0, 0} scroll={0, 0} mText="text to display.."
The rest of the times a pop-up is triggered (by user press on map icons) the view has non-zero parameters, and then line count works fine:
DEBUG/View(207): frame={7, 13, 209, 79} scroll={0, 0} DEBUG/View(207): mMeasureWidth=202 mMeasureHeight=66 DEBUG/View(207): privateFlags={HAS_BOUNDS} DEBUG/View(207): frame={7, 13, 209, 79} scroll={0, 0} mText="text to display.."
As a work-around I tried to draw an invisible PopupWindow before drawing the first pop-up, i.e trying to use it "twice the first time". This didn't help.. I also tried to invalidate the MapView which didn't work either.
Can anyone please suggest how to initiate the views properly so that I can use getLineCount() the way it is supposed to?
Thank you! Vanja