using Reflector on a label

boastrike

Member
Licensed User
Longtime User
Hopefully I can explain this accurately. I am working to get the width of a label using the reflector library. If I use it on a label defined in the designer it comes back with the width but if I declare one programatically then it comes back with 0. I'm not sure if this is something I have yet to learn with java classes or just forgetting something else. :BangHead:

Working returns values:

B4X:
Dim obj as Reflector

obj.Target=designerlabel

designerlabel.text = "Long text string here of several paragraphs..."

doevents
mywidth=obj.RunMethod("getWidth")
myheight=obj.RunMethod("getHeight")
doevents

Returns 0's:

B4X:
Dim obj as Reflector
Dim programlabel as label

programlabel.Initialize("programlabel")


obj.Target=programlabel

programlabel.text = "Long text string here of several paragraphs..."

doevents
mywidth=obj.RunMethod("getWidth")
myheight=obj.RunMethod("getHeight")
doevents

The text is actually converted richtext and loading it into a scrollview passed to customdialog. I am so close and like the clean look from the customdialog to display an initial welcome message that I can add images and links but am struggling with the autoformatting on this. I read where this reflector is a problem with ICS but hoping for a resolution on that soon as well.

Thanks, Jim
 

stevel05

Expert
Licensed User
Longtime User
Try calling designerlabel.Invalidate before you call the Reflection methods. Just curious why you want to use reflection and not just use label.width etc.

Edit: If that is all of your code, you haven't set the height and width for the label, you do this when you add it to the activity or panel. Activity.AddView(View,left etc.
 
Last edited:
Upvote 0

boastrike

Member
Licensed User
Longtime User
Stevel05,

Thanks for the suggestion. I am assuming you mean to try invalidating the programlabel as the designer one works. Unfortunately it did not resolve it. I am using the reflection to get the adjusted height and width after reformatting it with the richtext and multiline resizing so the scrollview and panels are sized right.

Yes this is only the snippets samples of code and I did set the width and size on the addview using pnlOnce.AddView(programlabel,0,0,-2,-2). The reflector does work perfect on the designer one it all fits and displays but I would like to use the customdialog if possible as it creates a nice compact modal pop-up bordered look. I can try to get more code and screen prints of how they differ in the morning.

Thanks, Jim
 
Upvote 0
Top