Android Question How do I get a remoteview Label.text

Bryan

Member
Licensed User
Longtime User
I abandoned a program I have been working on for nearly 2 years because I couldn't solve several problems with it. I Figured what I wanted to do couldn't be accomplished with B4A. I thought I'd give it another try again. I did finally manage to fix one serious bug I had. The other one is related to using a Label in a remote view (widget).

So, if I wanted to do MeasureMultilineTextHeight(Label1, Label1.Text) in a remote view (home screen widget) is there a way to do this? I cannot use Label1.text.

Thanks,
Bryan
 

stevel05

Expert
Licensed User
Longtime User
You don't need to use the actual label to measure the string height, you can create a dummy label with the same Font, on a dummy panel. It appears that the panel doesn't need to be added to an activity for it to work try this:

B4X:
    Dim P As Panel
    P.Initialize("")
    Dim L As Label
    L.Initialize("")
    P.AddView(L,0,0,150,30)
    Dim SU As StringUtils
    Log(SU.MeasureMultilineTextHeight(L,"Test "& CRLF & "Test2"))
 
Upvote 0

Bryan

Member
Licensed User
Longtime User
You don't need to use the actual label to measure the string height, you can create a dummy label with the same Font, on a dummy panel. It appears that the panel doesn't need to be added to an activity for it to work try this:

B4X:
    Dim P As Panel
    P.Initialize("")
    Dim L As Label
    L.Initialize("")
    P.AddView(L,0,0,150,30)
    Dim SU As StringUtils
    Log(SU.MeasureMultilineTextHeight(L,"Test "& CRLF & "Test2"))

I think this would work in an Activity but not in a Remoteview (home screen widget) as I need. Am I correct?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
What exactly are you trying to do? The size will be the same in an activity or in a widget. The text in the label can't change unless you change it, so you can know the size when you change it using this code.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are changing the text and need the Label to change size, set it's height to -2 (fit content)
 
Upvote 0

Bryan

Member
Licensed User
Longtime User
If you are changing the text and need the Label to change size, set it's height to -2 (fit content)
Sorry, I didn't give you the entire explanation. The text does change as buttons are pressed. The buttons selects an item from a list and is displayed in the label. The user can edit this list up to a maximum of 20 characters per item. I'm trying to keep the label as small as possible because it's part of a widget. So, the feature I need is to vary the text size to fit the label.

Bryan
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try this, you'll need to set the dummy label with the same typeface etc that you use for the label on the widget.
 

Attachments

  • WidgetTest.zip
    7.6 KB · Views: 203
Upvote 0

Bryan

Member
Licensed User
Longtime User
Try this, you'll need to set the dummy label with the same typeface etc that you use for the label on the widget.
Thank you for your help it is greatly appreciated. I will try this later today at when I get home. Will let you know how it works out.
Thanks again,
Bryan
 
Upvote 0

Bryan

Member
Licensed User
Longtime User
Try this, you'll need to set the dummy label with the same typeface etc that you use for the label on the widget.
You are certainly an expert. This looks like it's going to work very nicely. I couldn't figure out how to do this. You deserve a donation for the help. I will arrange it shortly with PayPal.
Thank you very much.
Bryan
 
Upvote 0
Top