Widget resizing, passing data, text cut off

Inman

Well-Known Member
Licensed User
Longtime User
Even though widgets were available in B4A for over a year, this is the first time one of my apps needed them. I went through the tutorials, questions, everything and figured out a lot. Still there are a few issues I am facing.

1. Is it possible to resize the labels and imageviews in a widget, on run time, with code?

2. My widget has a label, clicking upon which should open a link in the browser. This link changes every time. Normally if it was in an activity, I would have stored the link in label.tag and retrieved it in the label_click event using Sender. But in case of widgets I couldn't set the tag using code. Moreover trying to request Sender in label_click resulted in force close of the app. So how can this be done here?

3. Is it possible to enable setEllipsize for a label used in the widget, so that the text gets truncated properly with "..." in the end, instead of an abrupt cut off? If no, then how can I calculate the maximum number of characters that will fit within a label?
 
1. The size of the widget cannot be changed at runtime. You can make your widget large enough for the maximum required size with a transparent background.

2. You can store the link in a variable. Note that eventually Android will kill your process. This means that you should make such data persistent and save it to a file. You should then read the file in Service_Create.

3. You will not be able to use setEllipsize in this case. You can use Canvas.MeasureStringWidth to calculate the required width.
 
Upvote 0
Thanks Erel. I tried to use Canvas.MeasureStringWidth but couldn't calculate string cut off point. Couldn't find any threads on the topic either.

Fortunately since the width and height are finite, I could simply count the characters to find the cut off and get a substring. It is not perfect but works.
 
Upvote 0
Back
Top